Ruby GPGME::Error> Inappropriate ioctl for device - ruby-on-rails

I'm unable to import a key file. I'm using ruby 1.9.3 and ruby-gpgme
https://github.com/ueno/ruby-gpgme
require "gpgme"
begin
key = GPGME::Key.import(File.open("private.key"), {:password => "redacted"})
rescue GPGME::Error => g
puts g.inspect
puts g.message
puts g.code
puts g.source
end
Output
Inappropriate ioctl for device
More info:
/usr/local/opt/rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/gpgme-2.0.2/lib/gpgme/ctx.rb:43:in new': Inappropriate ioctl for device (GPGME::Error)
from /usr/local/opt/rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/gpgme-2.0.2/lib/gpgme/key.rb:120:inimport'
from gpgme.rb:17:in `'
Here is the ctx.rb file, but I don't get what could be causing the issue...
https://github.com/ueno/ruby-gpgme/blob/master/lib/gpgme/ctx.rb

The error was a result of some issue with gpgme. So I reinstalled gpgme. I used "brew gpgme". now it seems to be working.

Related

Errno::ENOTTY Inappropriate ioctl for device when connecting to a remote server through Net::SSH on SuSe (with Ruby on Rails 5.2.4)

My Ruby on Rails application remotely starts some scripts on a distant SuSe server (SUSE Linux Enterprise Server 15 SP2). It relies on the net-ssh gem which is declared in the Gemfile: gem 'net-ssh'.
The script is triggerd remotely through the following block:
Net::SSH.start(remote_host, remote_user, password: remote_password) do |ssh|
feed_back = ssh.exec!("#{event.statement}")
end
This works as expected as long as long as the Rails server runs on Windows Server 2016, which is my DEV environment. But when I deploy to the Validation environment, which is SUSE Linux Enterprise Server 15 SP2, I get this error message:
Errno::ENOTTY in myController#myMethod
Inappropriate ioctl for device
On another hand, issuing the SSH request through the command line - from SUSE to SUSE - works as expected too. Reading around I did not find a relevant parameter for the Net::SSH module to solve this.
Your suggestions are welcome!
I finally found out that the message refers to the operating mode of SSH: it requires a sort of terminal emulation - so called pty - wrapped into a SSH chanel.
So I implemented it this way:
Net::SSH.start(remote_host, remote_user, password: remote_password) do |session|
session.open_channel do |channel|
channel.request_pty do |ch, success|
raise "Error requesting pty" unless success
puts "------------ pty successfully obtained"
end
channel.exec "#{#task.statement}" do |ch, success|
abort "could not execute command" unless success
channel.on_data do |ch, data|
puts "------------ got stdout: #{data}"
#task.update_attribute(:return_value, data)
end
channel.on_extended_data do |ch, type, data|
puts "------------ got stderr: #{data}"
end
channel.on_close do |ch|
puts "------------ channel is closing!"
end
end
end
### Wait until the session closes
session.loop
end
This solved my issue.
Note:
The answer proposed above was only a part of the solution. The same error occured again with this source code when deploying to the production server.
The issue appears to be the password to the SSH target: I retyped it by hand instead of doing the usual copy/paste from MS Excel, and the SSH connection is now successful!
As the error raised is not a simple "connection refused", I suspect that the password string had a specific character encoding, or an unexpected ending character.
As the first proposed solution provides a working example, I leave it there.

NoMethodError: undefined method `bindings' for java.lang.NullPointerException

we're working on a ruby on rails (4.2.8) application which is running on jruby-1.7.25. It really is time to update this mummy to the latest version 9.1.7.0. We did that and for most of my colleagues it works out fine. But - guess what - not for me. Before posting my question here, I made sure that:
I have the same setup
Same DB content
The exactly same code
as the others, but I still get that stupid error which is
java.lang.NullPointerException and that's really all, the app is spitting out on any request.
I was digging for the last hours and found out, that the real issue is getting lost in the depth of logging. Finally I found, that I will see the real cause if I add a puts in the file vendor/jruby/2.3.0/gems/actionpack-4.2.8/lib/action_dispatch/middleware/show_exceptions.rb like:
class ShowExceptions
FAILSAFE_RESPONSE = [500, { 'Content-Type' => 'text/plain' },
["500 Internal Server Error\n" \
"If you are the administrator of this website, then please read this web " \
"application's log file and/or the web server's log file to find out what " \
"went wrong."]]
def initialize(app, exceptions_app)
#app = app
#exceptions_app = exceptions_app
end
def call(env)
#app.call(env)
rescue Exception => exception
puts "EXCEPTION: #{exception.inspect}\n#app: #{#app.inspect}\nENV: #{env.inspect}"
if env['action_dispatch.show_exceptions'] == false
raise exception
else
render_exception(env, exception)
end
end
The output is:
EXCEPTION: #<NoMethodError: undefined method `bindings' for java.lang.NullPointerException:Java::JavaLang::NullPointerException
#app and env print out kilobytes of data which probably do not help. Honestly, I'm kind of stuck here. How can it work on other machines while it fails on mine? Has anyone of you had a similar issue or any idea what causes this trouble?
Ah, some version infos
Puma: * Version 3.7.1 (jruby 9.1.7.0 - ruby 2.3.1), codename: Snowy Sagebrush
jruby: jruby 9.1.7.0 (2.3.1) 2017-01-11 68056ae Java HotSpot(TM) 64-Bit Server VM 24.79-b02 on 1.7.0_79-b15 +jit [darwin-x86_64]
java: java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
Mac OSX: 10.12.3 (16D32)
Thanks for any hints!

getting wrong ELF class warning while trying ruby script to SSH

I want to ssh to one of the linux servers and then run some commands. Below is the ruby script.
require 'socket'
require 'rubygems'
require 'net/ssh'
#hostname = "hostname"
#username = "user"
#password = "pass"
#cmd = "ls -alt"
begin
ssh = Net::SSH.start(#hostname, #username, :password => #password)
res = ssh.exec!(#cmd)
ssh.close
puts res
rescue
puts "Unable to connect to #{#hostname} using #{#username}/#{#password}"
end
It gives me the correct output but before giving the output it prints the following warning message:
ruby ssh.rb
Nov 5, 2014 3:21:02 PM jnr.netdb.NativeServicesDB load
WARNING: Failed to load native services db
java.lang.UnsatisfiedLinkError: /lib/libc.so.6: wrong ELF class: ELFCLASS32
at jnr.ffi.provider.jffi.NativeLibrary.loadNativeLibraries(NativeLibrary.java:87)
at jnr.ffi.provider.jffi.NativeLibrary.getNativeLibraries(NativeLibrary.java:70)
at jnr.ffi.provider.jffi.NativeLibrary.getSymbolAddress(NativeLibrary.java:49)
at jnr.ffi.provider.jffi.NativeLibrary.findSymbolAddress(NativeLibrary.java:59)
at jnr.ffi.provider.jffi.AsmLibraryLoader.generateInterfaceImpl(AsmLibraryLoader.java:125)
at jnr.ffi.provider.jffi.AsmLibraryLoader.loadLibrary(AsmLibraryLoader.java:63)
at jnr.ffi.provider.jffi.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:43)
at jnr.ffi.LibraryLoader.load(LibraryLoader.java:228)
at jnr.ffi.Library.loadLibrary(Library.java:123)
at jnr.ffi.Library.loadLibrary(Library.java:80)
at jnr.netdb.NativeServicesDB.load(NativeServicesDB.java:81)
at jnr.netdb.Service$ServicesDBSingletonHolder.load(Service.java:122)
at jnr.netdb.Service$ServicesDBSingletonHolder.<clinit>(Service.java:118)
I did some research and found this https://jira.codehaus.org/browse/JRUBY-7183 but did not understand the solution. Can somebody please guide me on this?
Thanks.

Paperclip File Not Found Error

I just switched from a paperclip rails plugin to a paperclip gem. The project is a rails 2.3 application and I am using paperclip 2.7.2 gem.
I am getting the following odd error:
identify: unable to open image `file': No such file or directory # error/blob.c/OpenBlob/2617.
identify: no decode delegate for this image format `file' # error/constitute.c/ReadImage/544.
Seems like paperclip is looking for a file called 'file' but I am not sure why. I didn't change any of the code we had before. It used to work, all I did was upgrade to a newer version and use a gem over a plugin.
Any ideas?
Update
It to be a bug in paper clip where it does not parse the content of the command properly. I dug deep into the paperclip source to find:
def run(cmd, arguments = "", local_options = {})
if options[:image_magick_path]
Paperclip.log("[DEPRECATION] :image_magick_path is deprecated and will be removed. Use :command_path instead")
end
command_path = options[:command_path] || options[:image_magick_path]
Cocaine::CommandLine.path = [Cocaine::CommandLine.path, command_path].flatten.compact.uniq
local_options = local_options.merge(:logger => logger) if logging? && (options[:log_command] || local_options[:log_command])
Cocaine::CommandLine.new(cmd, arguments, local_options).run
end
and
# Uses ImageMagick to determing the dimensions of a file, passed in as either a
# File or path.
# NOTE: (race cond) Do not reassign the 'file' variable inside this method as it is likely to be
# a Tempfile object, which would be eligible for file deletion when no longer referenced.
def self.from_file file
file_path = file.respond_to?(:path) ? file.path : file
raise(Paperclip::NotIdentifiedByImageMagickError.new("Cannot find the geometry of a file with a blank name")) if file_path.blank?
geometry = begin
Paperclip.run("identify", "-format %wx%h :file", :file => "#{file_path}[0]")
rescue Cocaine::ExitStatusError
""
rescue Cocaine::CommandNotFoundError => e
raise Paperclip::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.")
end
parse(geometry) ||
raise(NotIdentifiedByImageMagickError.new("#{file_path} is not recognized by the 'identify' command."))
end
The Paperclip.run command fails to replace the :file placeholder for some reason. I verified this by running the following on the commandline:
identify :file
Monkey patching the replacement by hand yields other errors where a similar thing happens.
Ok I managed to solve it.
It was a problem with Cocaine. Seems paperclip has a dependency on cocaine that only says it must be Cociane > 0.02. The latest version of Cocaine 0.4.2 (at the time of this writing) has a new API which is not backward compatible. You need to downgrade to Cocaine 0.3.2.
Simply put this in your Gemfile before paperclip:
gem "cocaine", "0.3.2"

Ruby on Rails rescuing from 'Errno::ENOENT'

I need to rescue from 'Errno::ENOENT' in a Ruby on Rails 3.0.4 application. I currently have controller with the following code:
begin
`lame #{parameters}`
rescue Errno::ENOENT
logger.info "command 'lame' not found: ensure LAME is installed"
end
However, the log code is never called, but the logs show:
script/rails: No such file or directory - lame ...
If I create a ruby script with same snippet, the exception is rescued.
In Ruby 1.8, Errno::ENOENT is not raised by shell execution / back-ticks - the error you're seeing is standard error, printed by the shell. If you want to detect this, I'd recommend looking for an exit code of 127:
`lame #{parameters} 2>&1`
if $?.exitstatus == 127
logger.info "command 'lame' not found: ensure LAME is installed"
end
However, this will raise Errno::ENOENT in Ruby 1.9.
You might consider checking the output from which lame instead:
lame_installed = system("which lame >/dev/null")
# or even better
lame_available = !(lame_path = `which lame`.strip).empty? && File.executable?(lame_path)
Further reading:
http://www.faqs.org/docs/abs/HTML/exitcodes.html

Resources