File: rdp.rb

package info (click to toggle)
vagrant 2.2.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,072 kB
  • sloc: ruby: 80,731; sh: 369; makefile: 9; lisp: 1
file content (56 lines) | stat: -rw-r--r-- 1,971 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require "vagrant/util/which"

module VagrantPlugins
  module HostLinux
    module Cap
      class RDP
        def self.rdp_client(env, rdp_info)
          # 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
              if Vagrant::Util::Platform.wsl?
                "mstsc.exe"
              else
                raise Vagrant::Errors::LinuxRDPClientNotFound
              end
            end

          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]}"
          when "mstsc.exe"
            # Setup password
            cmdKeyArgs = [
              "/add:#{rdp_info[:host]}:#{rdp_info[:port]}",
              "/user:#{rdp_info[:username]}",
              "/pass:#{rdp_info[:password]}",
            ]
            Vagrant::Util::Subprocess.execute("cmdkey.exe", *cmdKeyArgs)

            args = ["/v:#{rdp_info[:host]}:#{rdp_info[:port]}"]
            args += rdp_info[:extra_args] if rdp_info[:extra_args]
          end

          # Finally, run the client.
          Vagrant::Util::Subprocess.execute(rdp_client, *args)
        end
      end
    end
  end
end