Sha256: 741ce912bb2658f3343baa397dd44d550401a7764c2565f80a9244e9a32b3360

Contents?: true

Size: 1.85 KB

Versions: 48

Compression:

Stored size: 1.85 KB

Contents

require "pathname"
require "tmpdir"

require "vagrant/util/subprocess"

module VagrantPlugins
  module HostDarwin
    module Cap
      class RDP
        def self.rdp_client(env, rdp_info)
          config_path = self.generate_config_file(rdp_info)
          begin
            Vagrant::Util::Subprocess.execute("open", config_path.to_s)
          ensure
            # Note: this technically will never get run; neither would an
            # at_exit call. The reason is that `exec` replaces this process,
            # effectively the same as `kill -9`. This is solely here to prove
            # that and so that future developers do not waste a ton of time
            # try to identify why Vagrant is leaking RDP connection files.
            # There is a catch-22 here in that we can't delete the file before
            # we exec, and we can't delete the file after we exec :(.
            File.unlink(config_path) if File.file?(config_path)
          end
        end

        protected

        # Generates an RDP connection file and returns the resulting path.
        # @return [String]
        def self.generate_config_file(rdp_info)
          opts   = {
            "drivestoredirect:s"       => "*",
            "full address:s"           => "#{rdp_info[:host]}:#{rdp_info[:port]}",
            "prompt for credentials:i" => "1",
            "username:s"               => rdp_info[:username],
          }

          # Create the ".rdp" file
          t = ::Tempfile.new(["vagrant-rdp", ".rdp"]).tap do |f|
            f.binmode

            opts.each do |k, v|
              f.puts("#{k}:#{v}")
            end

            if rdp_info[:extra_args]
              rdp_info[:extra_args].each do |arg|
                f.puts("#{arg}")
              end
            end

            f.fsync
            f.close
          end

          return t.path
        end
      end
    end
  end
end

Version data entries

48 entries across 44 versions & 5 rubygems

Version Path
vagrant-unbundled-2.3.6.0 plugins/hosts/darwin/cap/rdp.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.3.3.0 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.3.2.0 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.19.0 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.18.0 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.16.0 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.14.0 plugins/hosts/darwin/cap/rdp.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.10.0 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.9.0 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.8.0 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.7.0 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.6.2 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.6.1 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.6.0 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.5.0 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.4.0 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.3.0 plugins/hosts/darwin/cap/rdp.rb
vagrant-unbundled-2.2.2.0 plugins/hosts/darwin/cap/rdp.rb