Sha256: 03e6b262e26a2e488a304000012be8e1905dd782bb0c1b6839ace64296306087

Contents?: true

Size: 1.74 KB

Versions: 3

Compression:

Stored size: 1.74 KB

Contents

require 'dl/import'
require 'dl/struct'

module Net; module SSH; module Kerberos;
  
  module Drivers

    # Some useful DL extensions.
	  module DLDriver
	    PTR_ENC = proc{|v| v && (DL::PtrData===v ? v : v.to_ptr) }
	    PTR_REF_ENC = proc{|v| (v.nil? ? DL::PtrData.new(v) : (DL::PtrData===v ? v : v.to_ptr)).ref }
	      
	    module ClassMethods
		    def PTR_DEC(t) proc{|v| v && t.new(v)} end
		    def PTR_REF_DEC(t) proc{|v| v && v.ptr && t.new(v.ptr)} end
		  
		    def struct2(fields, &block)
		      t = struct fields
		      return t unless block_given?
		      t.instance_variable_set :@methods, Module.new(&block)
		      class << t
		        alias :new_struct :new
		        def new(ptr)
		          mem = new_struct(ptr)
		          mem.extend @methods
		          mem
		        end
		      end
		      t
		    end
	    end
	    
			if RUBY_VERSION =~ /^1\.8/
				def self.included(base)
					base.extend DL::Importable
					base.extend ClassMethods
				end
			else
				def self.included(base)
					base.extend DL::Importer
					base.extend ClassMethods
				end
			end
		end

		@@available = []
    def self.available; @@available end

		if RUBY_PLATFORM.include?('win') && ! RUBY_PLATFORM.include?('dar'); then
		  begin require 'net/ssh/kerberos/drivers/sspi'; available << 'SSPI'
		  rescue => e
		    raise e unless RuntimeError === e and e.message =~ /^LoadLibrary: ([^\s]+)/
			  $stderr.puts "error: While loading Kerberos SSPI: failed to load library: #{$1}"
		  end
		end
		begin require 'net/ssh/kerberos/drivers/gss'; available << 'GSS'
		rescue => e; raise e if available.empty?
		end
			
		if available.empty?
		  $stderr.puts "error: Failed to a find a supported GSS implementation on this platform (#{RUBY_PLATFORM})"
		end
  end

end; end; end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
net-ssh-kerberos-0.2.3 lib/net/ssh/kerberos/drivers.rb
net-ssh-kerberos-0.2.2 lib/net/ssh/kerberos/drivers.rb
net-ssh-kerberos-0.2.1 lib/net/ssh/kerberos/drivers.rb