gssapi 0.1.5 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 1.0.0
@@ -17,6 +17,15 @@
17
17
  # You should have received a copy of the GNU General Public License along
18
18
  # with GSSAPI. If not, see <http://www.gnu.org/licenses/>.
19
19
  #############################################################################
20
+ require 'ffi'
21
+ module GSSAPI
22
+ module LibGSSAPI
23
+ extend FFI::Library
24
+
25
+ GSSAPI_LIB_TYPE = :mit unless defined?(GSSAPI_LIB_TYPE)
26
+ end
27
+ end
28
+
20
29
  require 'gssapi/exceptions'
21
30
  require 'gssapi/lib_gssapi'
22
31
  require 'gssapi/simple'
@@ -0,0 +1,24 @@
1
+ #############################################################################
2
+ # Copyright © 2010 Dan Wanek <dan.wanek@gmail.com>
3
+ #
4
+ #
5
+ # This file is part of the Ruby GSSAPI library.
6
+ #
7
+ # GSSAPI is free software: you can redistribute it and/or
8
+ # modify it under the terms of the GNU General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or (at
10
+ # your option) any later version.
11
+ #
12
+ # GSSAPI is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15
+ # Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License along
18
+ # with GSSAPI. If not, see <http://www.gnu.org/licenses/>.
19
+ #############################################################################
20
+ module GSSAPI
21
+ module LibGSSAPI
22
+ GSSAPI_LIB_TYPE = :heimdal
23
+ end
24
+ end
@@ -17,38 +17,20 @@
17
17
  # You should have received a copy of the GNU General Public License along
18
18
  # with GSSAPI. If not, see <http://www.gnu.org/licenses/>.
19
19
  #############################################################################
20
- require 'ffi'
21
-
20
+ require 'gssapi/lib_gssapi_loader'
22
21
  module GSSAPI
23
22
  module LibGSSAPI
24
- extend FFI::Library
25
-
26
- case RUBY_PLATFORM
27
- when /linux/
28
- # Some Ubuntu ship only with libgssapi_krb5, hence this hackery.
29
- # MIT is the only supported GSSAPI/Kerberos library at this time.
30
- ffi_lib File.basename Dir.glob("/usr/lib/libgssapi_*").sort.first, FFI::Library::LIBC
31
- when /darwin/
32
- ffi_lib '/usr/lib/libgssapi_krb5.dylib', FFI::Library::LIBC
33
- when /win/
34
- ffi_lib 'gssapi32' # Required the MIT Kerberos libraries to be installed
35
- ffi_convention :stdcall
36
- else
37
- raise LoadError, "This platform (#{RUBY_PLATFORM}) is not supported by ruby gssapi."
38
- end
39
23
 
40
24
  # Libc functions
41
25
 
42
26
  # void *malloc(size_t size);
43
- attach_function :malloc, [:size_t], :pointer
27
+ attach_function :malloc, [:uint32], :pointer
44
28
 
45
29
  # void *memcpy(void *dest, const void *src, size_t n);
46
- attach_function :memcpy, [:pointer, :pointer, :size_t], :pointer
47
-
30
+ attach_function :memcpy, [:pointer, :pointer, :uint32], :pointer
48
31
 
49
32
  typedef :uint32, :OM_uint32
50
33
 
51
-
52
34
  class GssOID < FFI::Struct
53
35
  layout :length => :OM_uint32,
54
36
  :elements => :pointer # pointer of :void
@@ -138,7 +120,7 @@ module GSSAPI
138
120
  self[:length] = val.length
139
121
  self[:value] = buff
140
122
  elsif(val.is_a?(Fixnum))
141
- buff = FFI::MemoryPointer.new :uint32
123
+ buff = FFI::MemoryPointer.new :OM_uint32
142
124
  buff.write_int val
143
125
  self[:length] = val.to_s.length
144
126
  self[:value] = buff
@@ -164,7 +146,7 @@ module GSSAPI
164
146
 
165
147
  def self.release(ptr)
166
148
  puts "Releasing ManagedGssBufferDesc at #{ptr.address.to_s(16)}" if $DEBUG
167
- min_stat = FFI::MemoryPointer.new :uint32
149
+ min_stat = FFI::MemoryPointer.new :OM_uint32
168
150
  maj_stat = LibGSSAPI.gss_release_buffer(min_stat, ptr)
169
151
  end
170
152
  end
@@ -214,14 +196,14 @@ module GSSAPI
214
196
  class GssNameT < GssPointer
215
197
  def self.release_ptr(name_ptr)
216
198
  puts "Releasing gss_name_t at #{name_ptr.address.to_s(16)}" if $DEBUG
217
- min_stat = FFI::MemoryPointer.new :uint32
199
+ min_stat = FFI::MemoryPointer.new :OM_uint32
218
200
  maj_stat = LibGSSAPI.gss_release_name(min_stat, name_ptr)
219
201
  end
220
202
  end
221
203
 
222
204
  class GssCtxIdT < GssPointer
223
205
  def self.release_ptr(context_ptr)
224
- min_stat = FFI::MemoryPointer.new :uint32
206
+ min_stat = FFI::MemoryPointer.new :OM_uint32
225
207
  # FIXME: change to GSS_C_NO_BUFFER
226
208
  empty_buff = LibGSSAPI::UnManagedGssBufferDesc.new
227
209
  empty_buff[:length] = 0
@@ -237,7 +219,7 @@ module GSSAPI
237
219
  # gss_cred_id_t
238
220
  class GssCredIdT < GssPointer
239
221
  def self.release_ptr(cred_ptr)
240
- min_stat = FFI::MemoryPointer.new :uint32
222
+ min_stat = FFI::MemoryPointer.new :OM_uint32
241
223
  maj_stat = LibGSSAPI.gss_release_cred(min_stat, cred_ptr)
242
224
  end
243
225
  end
@@ -255,7 +237,7 @@ module GSSAPI
255
237
  # buff_str[:length] = host_str.length
256
238
  # buff_str[:value] = FFI::MemoryPointer.from_string(host_str)
257
239
  # name = FFI::MemoryPointer.new :pointer # gss_name_t
258
- # min_stat = FFI::MemoryPointer.new :uint32
240
+ # min_stat = FFI::MemoryPointer.new :OM_uint32
259
241
  # maj_stat = GSSAPI::LibGSSAPI.gss_import_name(min_stat, buff_str.pointer, GSSAPI::LibGSSAPI.GSS_C_NT_HOSTBASED_SERVICE, name)
260
242
  # name = name.get_pointer(0)
261
243
  # Remember to free the allocated name (gss_name_t) space with gss_release_name
@@ -267,27 +249,30 @@ module GSSAPI
267
249
  # OM_uint32 gss_canonicalize_name(OM_uint32 * minor_status, const gss_name_t input_name, const gss_OID mech_type, gss_name_t * output_name)
268
250
  attach_function :gss_canonicalize_name, [:pointer, :pointer, :pointer, :pointer], :OM_uint32
269
251
 
270
- # OM_uint32 gss_oid_to_str(OM_uint32 *minor_status, const gss_OID oid, gss_buffer_t oid_str);
271
- # @example:
272
- # min_stat = FFI::MemoryPointer.new :uint32
273
- # oidstr = GSSAPI::LibGSSAPI::ManagedGssBufferDesc.new
274
- # maj_stat = GSSAPI::LibGSSAPI.gss_oid_to_str(min_stat, GSSAPI::LibGSSAPI.GSS_C_NT_HOSTBASED_SERVICE, oidstr.pointer)
275
- # oidstr[:value].read_string
276
- attach_function :gss_oid_to_str, [:pointer, :pointer, :pointer], :OM_uint32
277
-
278
- # TODO: Missing from Heimdal
279
- # OM_uint32 gss_str_to_oid(OM_uint32 *minor_status, const gss_buffer_t oid_str, gss_OID *oid);
280
- # @example: Simulate GSS_C_NT_HOSTBASED_SERVICE
281
- # min_stat = FFI::MemoryPointer.new :uint32
282
- # str = "{ 1 2 840 113554 1 2 1 4 }"
283
- # oidstr = GSSAPI::LibGSSAPI::UnManagedGssBufferDesc.new
284
- # oidstr[:length] = str.length
285
- # oidstr[:value] = FFI::MemoryPointer.from_string str
286
- # oid = FFI::MemoryPointer.new :pointer
287
- # min_stat = FFI::MemoryPointer.new :uint32
288
- # maj_stat = GSSAPI::LibGSSAPI.gss_str_to_oid(min_stat, oidstr.pointer, oid)
289
- # oid = GSSAPI::LibGSSAPI::GssOID.new(oid.get_pointer(0))
290
- #attach_function :gss_str_to_oid, [:pointer, :pointer, :pointer], :OM_uint32
252
+ begin
253
+ # OM_uint32 gss_oid_to_str(OM_uint32 *minor_status, const gss_OID oid, gss_buffer_t oid_str);
254
+ # @example:
255
+ # min_stat = FFI::MemoryPointer.new :OM_uint32
256
+ # oidstr = GSSAPI::LibGSSAPI::ManagedGssBufferDesc.new
257
+ # maj_stat = GSSAPI::LibGSSAPI.gss_oid_to_str(min_stat, GSSAPI::LibGSSAPI.GSS_C_NT_HOSTBASED_SERVICE, oidstr.pointer)
258
+ # oidstr[:value].read_string
259
+ attach_function :gss_oid_to_str, [:pointer, :pointer, :pointer], :OM_uint32
260
+
261
+ # OM_uint32 gss_str_to_oid(OM_uint32 *minor_status, const gss_buffer_t oid_str, gss_OID *oid);
262
+ # @example: Simulate GSS_C_NT_HOSTBASED_SERVICE
263
+ # min_stat = FFI::MemoryPointer.new :OM_uint32
264
+ # str = "{ 1 2 840 113554 1 2 1 4 }"
265
+ # oidstr = GSSAPI::LibGSSAPI::UnManagedGssBufferDesc.new
266
+ # oidstr[:length] = str.length
267
+ # oidstr[:value] = FFI::MemoryPointer.from_string str
268
+ # oid = FFI::MemoryPointer.new :pointer
269
+ # min_stat = FFI::MemoryPointer.new :OM_uint32
270
+ # maj_stat = GSSAPI::LibGSSAPI.gss_str_to_oid(min_stat, oidstr.pointer, oid)
271
+ # oid = GSSAPI::LibGSSAPI::GssOID.new(oid.get_pointer(0))
272
+ attach_function :gss_str_to_oid, [:pointer, :pointer, :pointer], :OM_uint32
273
+ rescue FFI::NotFoundError => ex
274
+ warn "WARNING: Could not load OID conversion methods. Check your GSSAPI C library for an update"
275
+ end
291
276
 
292
277
  # OM_uint32 gss_init_sec_context(OM_uint32 * minor_status, const gss_cred_id_t initiator_cred_handle,
293
278
  # gss_ctx_id_t * context_handle, const gss_name_t target_name, const gss_OID mech_type, OM_uint32 req_flags,
@@ -307,30 +292,44 @@ module GSSAPI
307
292
  # OM_uint32 gss_wrap(OM_uint32 * minor_status, const gss_ctx_id_t context_handle, int conf_req_flag,
308
293
  # gss_qop_t qop_req, const gss_buffer_t input_message_buffer, int * conf_state, gss_buffer_t output_message_buffer);
309
294
  # @example:
310
- # min_stat = FFI::MemoryPointer.new :uint32
295
+ # min_stat = FFI::MemoryPointer.new :OM_uint32
311
296
  # Remember to free the allocated output_message_buffer with gss_release_buffer
312
297
  attach_function :gss_wrap, [:pointer, :pointer, :int, :OM_uint32, :pointer, :pointer, :pointer], :OM_uint32
313
298
 
314
- # Mac version of krb5 does not support *_iov
315
- unless RUBY_PLATFORM =~ /darwin/
316
- # OM_uint32 GSSAPI_LIB_FUNCTION gss_wrap_iov( OM_uint32 * minor_status, gss_ctx_id_t context_handle,
317
- # int conf_req_flag, gss_qop_t qop_req, int * conf_state, gss_iov_buffer_desc * iov, int iov_count );
299
+ # Some versions of GSSAPI might not have support for IOV yet.
300
+ begin
301
+ # OM_uint32 GSSAPI_LIB_FUNCTION gss_wrap_iov( OM_uint32 * minor_status, gss_ctx_id_t context_handle,
302
+ # int conf_req_flag, gss_qop_t qop_req, int * conf_state, gss_iov_buffer_desc * iov, int iov_count );
318
303
  attach_function :gss_wrap_iov, [:pointer, :pointer, :int, :OM_uint32, :pointer, :pointer, :int], :OM_uint32
319
304
 
320
305
  # OM_uint32 GSSAPI_LIB_FUNCTION gss_unwrap_iov ( OM_uint32 * minor_status, gss_ctx_id_t context_handle,
321
306
  # int * conf_state, gss_qop_t * qop_state, gss_iov_buffer_desc * iov, int iov_count )
322
307
  attach_function :gss_unwrap_iov, [:pointer, :pointer, :pointer, :pointer, :pointer, :int], :OM_uint32
308
+
309
+ # OM_uint32 GSSAPI_LIB_CALL gss_wrap_iov_length ( OM_uint32 * minor_status, gss_ctx_id_t context_handle,
310
+ # int conf_req_flag, gss_qop_t qop_req, int * conf_state, gss_iov_buffer_desc * iov, int iov_count)
311
+ attach_function :gss_wrap_iov_length, [:pointer, :pointer, :int, :OM_uint32, :pointer, :pointer, :int], :OM_uint32
312
+ rescue FFI::NotFoundError => ex
313
+ warn "WARNING: Could not load IOV methods. Check your GSSAPI C library for an update"
323
314
  end
324
315
 
325
- # TODO: Missing from Heimdal
326
- # OM_uint32 gss_wrap_aead(OM_uint32 * minor_status, gss_ctx_id_t context_handle, int conf_req_flag, gss_qop_t qop_req, gss_buffer_t input_assoc_buffer,
327
- # gss_buffer_t input_payload_buffer, int * conf_state, gss_buffer_t output_message_buffer);
328
- #attach_function :gss_wrap_aead, [:pointer, :pointer, :int, :OM_uint32, :pointer, :pointer, :pointer, :pointer], :OM_uint32
316
+ begin
317
+ # OM_uint32 gss_wrap_aead(OM_uint32 * minor_status, gss_ctx_id_t context_handle, int conf_req_flag,
318
+ # gss_qop_t qop_req, gss_buffer_t input_assoc_buffer,
319
+ # gss_buffer_t input_payload_buffer, int * conf_state, gss_buffer_t output_message_buffer);
320
+ attach_function :gss_wrap_aead, [:pointer, :pointer, :int, :OM_uint32, :pointer, :pointer, :pointer, :pointer], :OM_uint32
321
+
322
+ # OM_uint32 gss_unwrap_aead(OM_uint32 * minor_status, gss_ctx_id_t context_handle, gss_buffer_t input_message_buffer,
323
+ # gss_buffer_t input_assoc_buffer, gss_buffer_t output_payload_buffer, int * conf_state, gss_qop_t * qop_state);
324
+ attach_function :gss_unwrap_aead, [:pointer,:pointer,:pointer,:pointer,:pointer,:pointer,:pointer], :OM_uint32
325
+ rescue FFI::NotFoundError => ex
326
+ warn "WARNING: Could not load AEAD methods. Check your GSSAPI C library for an update"
327
+ end
329
328
 
330
329
  # OM_uint32 gss_unwrap(OM_uint32 * minor_status, const gss_ctx_id_t context_handle,
331
330
  # const gss_buffer_t input_message_buffer, gss_buffer_t output_message_buffer, int * conf_state, gss_qop_t * qop_state);
332
331
  # @example:
333
- # min_stat = FFI::MemoryPointer.new :uint32
332
+ # min_stat = FFI::MemoryPointer.new :OM_uint32
334
333
  # Remember to free the allocated output_message_buffer with gss_release_buffer
335
334
  attach_function :gss_unwrap, [:pointer, :pointer, :pointer, :pointer, :pointer, :pointer], :OM_uint32
336
335
 
@@ -0,0 +1,53 @@
1
+ #############################################################################
2
+ # Copyright © 2010 Dan Wanek <dan.wanek@gmail.com>
3
+ #
4
+ #
5
+ # This file is part of the Ruby GSSAPI library.
6
+ #
7
+ # GSSAPI is free software: you can redistribute it and/or
8
+ # modify it under the terms of the GNU General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or (at
10
+ # your option) any later version.
11
+ #
12
+ # GSSAPI is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15
+ # Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License along
18
+ # with GSSAPI. If not, see <http://www.gnu.org/licenses/>.
19
+ #############################################################################
20
+ module GSSAPI
21
+ module LibGSSAPI
22
+
23
+ # Heimdal supported the *_iov functions befor MIT did so in some OS distributions if
24
+ # you need IOV support and MIT does not provide it try the Heimdal libs and then
25
+ # before doing a "require 'gssapi'" do a "require 'gssapi/heimdal'" and that will attempt
26
+ # to load the Heimdal libs
27
+ case RUBY_PLATFORM
28
+ when /linux/
29
+ case GSSAPI_LIB_TYPE
30
+ when :mit
31
+ GSSAPI_LIB = 'libgssapi_krb5.so.2'
32
+ when :heimdal
33
+ GSSAPI_LIB = 'libgssapi.so.2'
34
+ end
35
+ ffi_lib GSSAPI_LIB, FFI::Library::LIBC
36
+ when /darwin/
37
+ case GSSAPI_LIB_TYPE
38
+ when :mit
39
+ GSSAPI_LIB = '/usr/lib/libgssapi_krb5.dylib'
40
+ when :heimdal
41
+ # use Heimdal Kerberos since Mac MIT Kerberos is OLD. Do a "require 'gssapi/heimdal'" first
42
+ GSSAPI_LIB = '/usr/heimdal/lib/libgssapi.dylib'
43
+ end
44
+ ffi_lib GSSAPI_LIB, FFI::Library::LIBC
45
+ when /mswin|mingw32|windows/
46
+ ffi_lib 'gssapi32' # Required the MIT Kerberos libraries to be installed
47
+ ffi_convention :stdcall
48
+ else
49
+ raise LoadError, "This platform (#{RUBY_PLATFORM}) is not supported by ruby gssapi."
50
+ end
51
+
52
+ end
53
+ end
@@ -73,7 +73,7 @@ module GSSAPI
73
73
  if(opts[:flags])
74
74
  flags = opts[:flags]
75
75
  else
76
- flags = (LibGSSAPI::GSS_C_MUTUAL_FLAG | LibGSSAPI::GSS_C_SEQUENCE_FLAG)
76
+ flags = (LibGSSAPI::GSS_C_MUTUAL_FLAG | LibGSSAPI::GSS_C_SEQUENCE_FLAG | LibGSSAPI::GSS_C_CONF_FLAG | LibGSSAPI::GSS_C_INTEG_FLAG)
77
77
  flags |= LibGSSAPI::GSS_C_DELEG_FLAG if opts[:delegate]
78
78
  flags |= LibGSSAPI::GSS_C_DELEG_POLICY_FLAG if opts[:delegate]
79
79
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gssapi
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.5
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dan Wanek
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-03 00:00:00 -06:00
13
+ date: 2011-04-29 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -43,7 +43,9 @@ files:
43
43
  - gssapi.gemspec
44
44
  - lib/gssapi.rb
45
45
  - lib/gssapi/exceptions.rb
46
+ - lib/gssapi/heimdal.rb
46
47
  - lib/gssapi/lib_gssapi.rb
48
+ - lib/gssapi/lib_gssapi_loader.rb
47
49
  - lib/gssapi/simple.rb
48
50
  - preamble
49
51
  has_rdoc: true