Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting Multiple Servers #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions lib/sshkit/sudo/interaction_handler.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module SSHKit
module Sudo
class DefaultInteractionHandler
MUTEX = Mutex.new

def wrong_password; self.class.wrong_password; end
def password_prompt; self.class.password_prompt; end

Expand All @@ -12,15 +14,17 @@ def on_data(command, stream_name, data, channel)
SSHKit::Sudo.password_cache[password_cache_key(command.host)] = nil
end
if data =~ password_prompt
key = password_cache_key(command.host)
pass = SSHKit::Sudo.password_cache[key]
unless pass
print data
pass = $stdin.noecho(&:gets)
puts ''
SSHKit::Sudo.password_cache[key] = pass
MUTEX.synchronize do
key = password_cache_key(command.host)
pass = SSHKit::Sudo.password_cache[key]
unless pass
print data
pass = $stdin.noecho(&:gets)
puts ''
SSHKit::Sudo.password_cache[key] = pass
end
channel.send_data(pass)
end
channel.send_data(pass)
end
end

Expand Down