From 879977832cb4161638eb3bcf125eb05c495da48a Mon Sep 17 00:00:00 2001 From: Eric Winkelmann Date: Mon, 2 Nov 2015 23:39:06 -0800 Subject: [PATCH 1/2] Prefer xfreerdp for RDP connections on Linux hosts. Rather than only using rdesktop (which does not work properly with newer versions of RDP), use xfreerdp if available and fall back to rdesktop if not. --- plugins/hosts/linux/cap/rdp.rb | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/plugins/hosts/linux/cap/rdp.rb b/plugins/hosts/linux/cap/rdp.rb index 7146ef890..61f231f7b 100644 --- a/plugins/hosts/linux/cap/rdp.rb +++ b/plugins/hosts/linux/cap/rdp.rb @@ -5,17 +5,35 @@ module VagrantPlugins module Cap class RDP def self.rdp_client(env, rdp_info) - if !Vagrant::Util::Which.which("rdesktop") - raise Vagrant::Errors::LinuxRDesktopNotFound - end + # Detect if an RDP client is available. + # Prefer xfreerdp as it supports newer versions of RDP. + rdp_client = + if Vagrant::Util::Which.which("xfreerdp") + "xfreerdp" + elsif Vagrant::Util::Which.which("rdesktop") + "rdesktop" + else + raise Vagrant::Errors::LinuxRDesktopNotFound + end args = [] - args << "-u" << rdp_info[:username] - args << "-p" << rdp_info[:password] if rdp_info[:password] - args += rdp_info[:extra_args] if rdp_info[:extra_args] - args << "#{rdp_info[:host]}:#{rdp_info[:port]}" - Vagrant::Util::Subprocess.execute("rdesktop", *args) + # Build appropriate arguments for the RDP client. + case rdp_client + when "xfreerdp" + args << "/u:#{rdp_info[:username]}" + args << "/p:#{rdp_info[:password]}" if rdp_info[:password] + args << "/v:#{rdp_info[:host]}:#{rdp_info[:port]}" + args += rdp_info[:extra_args] if rdp_info[:extra_args] + when "rdesktop" + args << "-u" << rdp_info[:username] + args << "-p" << rdp_info[:password] if rdp_info[:password] + args += rdp_info[:extra_args] if rdp_info[:extra_args] + args << "#{rdp_info[:host]}:#{rdp_info[:port]}" + end + + # Finally, run the client. + Vagrant::Util::Subprocess.execute(rdp_client, *args) end end end From e687f81fce3ae12d8d89a6ca11811ca2c31b2c7a Mon Sep 17 00:00:00 2001 From: Eric Winkelmann Date: Mon, 2 Nov 2015 23:42:01 -0800 Subject: [PATCH 2/2] Re-word Linux RDP error to include `xfreerdp`. Changed the name of the error LinuxRDesktopNotFound to LinuxRDPClientNotFound and re-worded error text in templates/locales/en.yml to include `xfreerdp` when listing supported RDP clients. --- lib/vagrant/errors.rb | 4 ++-- plugins/hosts/linux/cap/rdp.rb | 2 +- templates/locales/en.yml | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 906b8d9bc..aee0f3472 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -408,8 +408,8 @@ module Vagrant error_key(:linux_nfs_mount_failed) end - class LinuxRDesktopNotFound < VagrantError - error_key(:linux_rdesktop_not_found) + class LinuxRDPClientNotFound < VagrantError + error_key(:linux_rdp_client_not_found) end class LocalDataDirectoryNotAccessible < VagrantError diff --git a/plugins/hosts/linux/cap/rdp.rb b/plugins/hosts/linux/cap/rdp.rb index 61f231f7b..76476fc9b 100644 --- a/plugins/hosts/linux/cap/rdp.rb +++ b/plugins/hosts/linux/cap/rdp.rb @@ -13,7 +13,7 @@ module VagrantPlugins elsif Vagrant::Util::Which.which("rdesktop") "rdesktop" else - raise Vagrant::Errors::LinuxRDesktopNotFound + raise Vagrant::Errors::LinuxRDPClientNotFound end args = [] diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 9e8c680aa..8dce0806b 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -818,10 +818,11 @@ en: that the NFS client software is properly installed, and consult any resources specific to the linux distro you're using for more information on how to do this. - linux_rdesktop_not_found: |- - The `rdesktop` application was not found. Vagrant requires this - in order to connect via RDP to the Vagrant environment. Please ensure - this application is installed and available on the path and try again. + linux_rdp_client_not_found: |- + An appropriate RDP client was not found. Vagrant requires either + `xfreerdp` or `rdesktop` in order to connect via RDP to the Vagrant + environment. Please ensure one of these applications is installed and + available on the path and try again. machine_action_locked: |- An action '%{action}' was attempted on the machine '%{name}', but another process is already executing an action on the machine.