WinRb / WinRM

Ruby library for Windows Remote Management
Apache License 2.0
412 stars 117 forks source link

japanese username - invalid byte sequence #276

Closed ebgc closed 4 months ago

ebgc commented 7 years ago

hi

using below script throws an error. trying it with username 'user' and it works.

-- 1.rb -----------8<---------------

require 'winrm'

user = "サザ" pass = 'secret' end = '1.2.3.4'

opts = { endpoint: "http://#{end}/wsman", user: user, password: pass, overall_timeout: 5, retry_limit: 1, retry_delay: 1 }

conn = WinRM::Connection.new(opts) conn.shell(:cmd) do |shell| output = shell.run("dir") do |stdout, stderr| p "stdout: #{stdout}" p "stderr: #{stderr}" end puts "The script exited with exit code #{output.exitcode}" end -- 1.rb ----------------->8-----------------

running this gives and error: ----------------- execute and error ----------------------

> bundle exec ruby 1.rb

/Users/user/dddd/bundles/ruby/2.2.0/gems/rubyntlm-0.6.2/lib/net/ntlm.rb:164:in upcase': invalid byte sequence in UTF-8 (ArgumentError) from /Users/user/dddd/bundles/ruby/2.2.0/gems/rubyntlm-0.6.2/lib/net/ntlm.rb:164:inntlmv2_hash' from /Users/user/dddd/bundles/ruby/2.2.0/gems/rubyntlm-0.6.2/lib/net/ntlm/client/session.rb:192:in ntlmv2_hash' from /Users/user/dddd/bundles/ruby/2.2.0/gems/rubyntlm-0.6.2/lib/net/ntlm/client/session.rb:196:incalculate_user_session_key!' from /Users/user/dddd/bundles/ruby/2.2.0/gems/rubyntlm-0.6.2/lib/net/ntlm/client/session.rb:27:in authenticate!' from /Users/user/dddd/bundles/ruby/2.2.0/gems/rubyntlm-0.6.2/lib/net/ntlm/client.rb:36:ininit_context' from /Users/user/dddd/bundles/ruby/2.2.0/gems/winrm-2.2.3/lib/winrm/http/transport.rb:229:in init_auth' from /Users/user/dddd/bundles/ruby/2.2.0/gems/winrm-2.2.3/lib/winrm/http/transport.rb:168:insend_request' from /Users/user/dddd/bundles/ruby/2.2.0/gems/winrm-2.2.3/lib/winrm/shells/cmd.rb:56:in open_shell' from /Users/user/dddd/bundles/ruby/2.2.0/gems/winrm-2.2.3/lib/winrm/shells/base.rb:168:inblock in open' from /Users/user/dddd/bundles/ruby/2.2.0/gems/winrm-2.2.3/lib/winrm/shells/retryable.rb:37:in retryable' from /Users/user/dddd/bundles/ruby/2.2.0/gems/winrm-2.2.3/lib/winrm/shells/base.rb:166:inopen' from /Users/user/dddd/bundles/ruby/2.2.0/gems/winrm-2.2.3/lib/winrm/shells/base.rb:129:in with_command_shell' from /Users/user/dddd/bundles/ruby/2.2.0/gems/winrm-2.2.3/lib/winrm/shells/base.rb:81:inrun' from 1.rb:20:in block in <main>' from /Users/user/dddd/bundles/ruby/2.2.0/gems/winrm-2.2.3/lib/winrm/connection.rb:44:inshell' from 1.rb:19:in `

' ----------------- execute and error ----------------------

any idea ?

MikaelSmith commented 6 years ago

I'm encountering something that I think is similar. When I send and echo µsomemessage - where µ is a valid character in both UTF-8 and Windows-1252 (my target system's encoding) - I get 'invalid byte sequence' when run from Windows (but behaves okay from macOS/Linux). In particular

Update: this seems to specifically affect Ruby 2.3 on Windows. Seems fixed under Ruby 2.4.

pcai commented 4 months ago

Hi - looking at the trace of the original issue, this bug is in rubyntlm and should be addressed in https://github.com/WinRb/rubyntlm/pull/56

For @MikaelSmith's issue - glad to hear this is not an issue in ruby 2.4, but if you can reproduce, please provide a stacktrace. Thanks