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

force_encoding': can't modify frozen String (RuntimeError) #221

Closed
wtlinnertz opened this issue Sep 8, 2016 · 4 comments
Closed

force_encoding': can't modify frozen String (RuntimeError) #221

wtlinnertz opened this issue Sep 8, 2016 · 4 comments
Labels

Comments

@wtlinnertz
Copy link

wtlinnertz commented Sep 8, 2016

First off let me say that this is my first time using Ruby and I am posting this here to help other Ruby newbs who may get this error. I am trying to use RunDeck on Cent OS 7 to manage Windows servers using WinRM. I created a RunDeck plugin to pass commands through to Windows servers using this Ruby WinRM module. However, when passing the password to WinRM like so:

#!/usr/bin/ruby

require 'winrm'

puts 'starting ruby'

_host_command = ENV['RD_EXEC_COMMAND'] 
_host_name = ENV['RD_NODE_HOSTNAME']
_host_name = 'server name goes here'
_host_endpoint = "http://#{_host_name}:5985/wsman"
_host_username = ENV['RD_OPTION_USER_NAME']
_host_password = ENV['RD_SECUREOPTION_PASSWORD']

opts = {
  endpoint: _host_endpoint,
  user: _host_username,
  password: _host_password
}
conn = WinRM::Connection.new(opts)
conn.shell(:cmd) do |shell|
  shell.run(_host_command) do |stdout, stderr|
    STDOUT.print stdout
    STDERR.print stderr
  end
end

I receive the following error:

/usr/local/share/gems/gems/rubyntlm-0.6.0/lib/net/ntlm/encode_util.rb:42:in force_encoding': can't modify frozen String (RuntimeError)`

I had to change the password assignment line to the following to get it to work:

_host_password = ENV['RD_SECUREOPTION_PASSWORD'].dup

Hope this helps a future Ruby newb.

Cheers,
Todd

@sneal
Copy link
Member

sneal commented Sep 8, 2016

This seems like a library usability issues to me, I wouldn't expect the call to fail just because the string is frozen.

@sneal sneal added the bug label Sep 8, 2016
@mwrock
Copy link
Member

mwrock commented Sep 8, 2016

I think I have run into this before. rubyntlm mutates the encoding of the given password. So if you pass it a value from the ENV, then this error gets raised. We probably want to put a dup in rubyntlm to protetc from this.

@mwrock
Copy link
Member

mwrock commented Sep 15, 2016

submitted WinRb/rubyntlm#30 to fix

@mwrock
Copy link
Member

mwrock commented Sep 15, 2016

closed via WinRb/rubyntlm#30

@mwrock mwrock closed this as completed Sep 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants