gssapi 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -48,6 +48,7 @@ module GSSAPI
48
48
 
49
49
  typedef :uint32, :OM_uint32
50
50
 
51
+
51
52
  class GssOID < FFI::Struct
52
53
  layout :length => :OM_uint32,
53
54
  :elements => :pointer # pointer of :void
@@ -57,7 +58,6 @@ module GSSAPI
57
58
  end
58
59
  end
59
60
 
60
-
61
61
  # This is a generic Managed Struct subclass that hides the [] methods.
62
62
  # Classes that implement this class should provide accessor methods to get to the attributes.
63
63
  class GssMStruct < FFI::ManagedStruct
@@ -72,14 +72,53 @@ module GSSAPI
72
72
  end
73
73
  end
74
74
 
75
+ # This is a generic Unmanaged Struct subclass that hides the [] methods.
76
+ # Classes that implement this class should provide accessor methods to get to the attributes.
77
+ class GssUMStruct < FFI::Struct
78
+ private
79
+
80
+ def [](key)
81
+ super(key)
82
+ end
83
+
84
+ def []=(key,val)
85
+ super(key,val)
86
+ end
87
+ end
88
+
89
+ # This module provides a layout for both the managed and unmanaged GssBufferDesc structs.
90
+ module GssBufferDescLayout
91
+ def self.included(base)
92
+ base.class_eval do
93
+ layout :length => :size_t,
94
+ :value => :pointer # pointer of :void
95
+
96
+ def length
97
+ self[:length]
98
+ end
99
+
100
+ def value
101
+ if(self[:length] == 0)
102
+ nil
103
+ else
104
+ self[:value].read_string(self[:length])
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+
75
111
  # This class implements the gss_buffer_desc type. Use #pointer to emulate gss_buffer_t
112
+ # If you are setting the value of the buffer and it is not being set from the function
113
+ # this is the type of buffer you should use. If the buffer is being allocated and set
114
+ # inside the function you should use a ManagedGssBufferDesc instead so gss_release_buffer
115
+ # is called for it. It states in the manpage for each gss function whether or not
116
+ # gss_release_buffer needs to be called or not.
76
117
  # @example
77
- # buff = GssBufferDesc.new
118
+ # buff = UnManagedGssBufferDesc.new
78
119
  # buff.value = "This is a test"
79
- class GssBufferDesc < GssMStruct
80
- layout :length => :size_t,
81
- :value => :pointer # pointer of :void
82
-
120
+ class UnManagedGssBufferDesc < GssUMStruct
121
+ include GssBufferDescLayout
83
122
  def initialize(ptr = nil)
84
123
  if(ptr.nil?)
85
124
  super(FFI::Pointer.new(FFI::MemoryPointer.new(self.size)))
@@ -95,41 +134,38 @@ module GSSAPI
95
134
  self[:length] = 0
96
135
  self[:value] = val
97
136
  elsif(val.is_a?(String))
98
- rbuff = FFI::MemoryPointer.from_string(val)
99
- buff = LibGSSAPI.malloc(rbuff.size)
100
- LibGSSAPI.memcpy(buff,rbuff,rbuff.size)
137
+ buff = FFI::MemoryPointer.from_string(val)
101
138
  self[:length] = val.length
102
139
  self[:value] = buff
103
140
  elsif(val.is_a?(Fixnum))
104
- rbuff = FFI::MemoryPointer.new :uint32
105
- buff = LibGSSAPI.malloc(rbuff.size)
106
- LibGSSAPI.memcpy(buff,rbuff,rbuff.size)
141
+ buff = FFI::MemoryPointer.new :uint32
142
+ buff.write_int val
107
143
  self[:length] = val.to_s.length
108
144
  self[:value] = buff
109
145
  else
110
146
  raise StandardError, "Can't handle type #{val.class.name}"
111
147
  end
112
148
  end
149
+ end
113
150
 
114
- def length
115
- self[:length]
116
- end
117
-
118
- def value
119
- if(self[:length] == 0)
120
- nil
151
+ # This class implements the gss_buffer_desc type. Use #pointer to emulate gss_buffer_t
152
+ # Only functions that need to call gss_release_buffer should use this type. It states
153
+ # in the manpage for each function whether or not it should be called. If it does not
154
+ # you should be using UnManagedGssBufferDesc instead.
155
+ class ManagedGssBufferDesc < GssMStruct
156
+ include GssBufferDescLayout
157
+ def initialize(ptr = nil)
158
+ if(ptr.nil?)
159
+ super(FFI::Pointer.new(FFI::MemoryPointer.new(self.size)))
121
160
  else
122
- self[:value].read_string(self[:length])
161
+ super(ptr)
123
162
  end
124
163
  end
125
164
 
126
165
  def self.release(ptr)
127
- puts "FIXME: Not Releasing MGssBufferDesc at #{ptr.address.to_s(16)}" if $DEBUG
128
- #min_stat = FFI::MemoryPointer.new :uint32
129
- # FIXME: This causes Segfaults and I'm not sure where they're coming from at this time.
130
- # this is a horrible fix, but most instances should be fairly short lived so it's all
131
- # I got right now.
132
- #maj_stat = LibGSSAPI.gss_release_buffer(min_stat, ptr)
166
+ puts "Releasing ManagedGssBufferDesc at #{ptr.address.to_s(16)}" if $DEBUG
167
+ min_stat = FFI::MemoryPointer.new :uint32
168
+ maj_stat = LibGSSAPI.gss_release_buffer(min_stat, ptr)
133
169
  end
134
170
  end
135
171
 
@@ -141,20 +177,18 @@ module GSSAPI
141
177
  # iov_buff[:buffer][:value] = str
142
178
  class GssIOVBufferDesc < FFI::Struct
143
179
  layout :type => :OM_uint32,
144
- :buffer => GssBufferDesc
180
+ :buffer => UnManagedGssBufferDesc
145
181
  end
146
-
182
+
147
183
  class GssChannelBindingsStruct < FFI::Struct
148
184
  layout :initiator_addrtype => :OM_uint32,
149
- :initiator_address => GssBufferDesc,
150
- :acceptor_addrtype => :OM_uint32,
151
- :acceptor_address => GssBufferDesc,
152
- :application_data => GssBufferDesc
185
+ :initiator_address => UnManagedGssBufferDesc,
186
+ :acceptor_addrtype => :OM_uint32,
187
+ :acceptor_address => UnManagedGssBufferDesc,
188
+ :application_data => UnManagedGssBufferDesc
153
189
 
154
190
  no_chn_bind = FFI::MemoryPointer.new :pointer #
155
- no_chn_bind.write_int 0
156
-
157
-
191
+ no_chn_bind.write_int 0
158
192
  end
159
193
 
160
194
  # This s a generic AutoPointer. Gss pointers that implement this class should also implement a
@@ -188,7 +222,8 @@ module GSSAPI
188
222
  class GssCtxIdT < GssPointer
189
223
  def self.release_ptr(context_ptr)
190
224
  min_stat = FFI::MemoryPointer.new :uint32
191
- empty_buff = LibGSSAPI::GssBufferDesc.new
225
+ # FIXME: change to GSS_C_NO_BUFFER
226
+ empty_buff = LibGSSAPI::UnManagedGssBufferDesc.new
192
227
  empty_buff[:length] = 0
193
228
  empty_buff[:value] = nil
194
229
  maj_stat = LibGSSAPI.gss_delete_sec_context(min_stat, context_ptr, empty_buff.pointer)
@@ -216,7 +251,7 @@ module GSSAPI
216
251
  # OM_uint32 gss_import_name(OM_uint32 * minor_status, const gss_buffer_t input_name_buffer, const gss_OID input_name_type, gss_name_t * output_name);
217
252
  # @example:
218
253
  # host_str = 'host@example.com'
219
- # buff_str = GSSAPI::LibGSSAPI::GssBufferDesc.new
254
+ # buff_str = GSSAPI::LibGSSAPI::UnManagedGssBufferDesc.new
220
255
  # buff_str[:length] = host_str.length
221
256
  # buff_str[:value] = FFI::MemoryPointer.from_string(host_str)
222
257
  # name = FFI::MemoryPointer.new :pointer # gss_name_t
@@ -235,7 +270,7 @@ module GSSAPI
235
270
  # OM_uint32 gss_oid_to_str(OM_uint32 *minor_status, const gss_OID oid, gss_buffer_t oid_str);
236
271
  # @example:
237
272
  # min_stat = FFI::MemoryPointer.new :uint32
238
- # oidstr = GSSAPI::LibGSSAPI::GssBufferDesc.new
273
+ # oidstr = GSSAPI::LibGSSAPI::ManagedGssBufferDesc.new
239
274
  # maj_stat = GSSAPI::LibGSSAPI.gss_oid_to_str(min_stat, GSSAPI::LibGSSAPI.GSS_C_NT_HOSTBASED_SERVICE, oidstr.pointer)
240
275
  # oidstr[:value].read_string
241
276
  attach_function :gss_oid_to_str, [:pointer, :pointer, :pointer], :OM_uint32
@@ -245,7 +280,7 @@ module GSSAPI
245
280
  # @example: Simulate GSS_C_NT_HOSTBASED_SERVICE
246
281
  # min_stat = FFI::MemoryPointer.new :uint32
247
282
  # str = "{ 1 2 840 113554 1 2 1 4 }"
248
- # oidstr = GSSAPI::LibGSSAPI::GssBufferDesc.new
283
+ # oidstr = GSSAPI::LibGSSAPI::UnManagedGssBufferDesc.new
249
284
  # oidstr[:length] = str.length
250
285
  # oidstr[:value] = FFI::MemoryPointer.from_string str
251
286
  # oid = FFI::MemoryPointer.new :pointer
@@ -419,8 +454,7 @@ module GSSAPI
419
454
  GSS_C_NO_CONTEXT = FFI::Pointer.new(:pointer, 0) # ((gss_ctx_id_t) 0)
420
455
  GSS_C_NO_CREDENTIAL = FFI::Pointer.new(:pointer, 0) # ((gss_cred_id_t) 0)
421
456
  GSS_C_NO_CHANNEL_BINDINGS = FFI::Pointer.new(:pointer, 0) # ((gss_channel_bindings_t) 0)
422
- GSS_C_EMPTY_BUFFER = GssBufferDesc.new
423
-
457
+ GSS_C_EMPTY_BUFFER = ManagedGssBufferDesc.new
424
458
 
425
459
  end #end LibGSSAPI
426
460
  end #end GSSAPI
@@ -43,7 +43,7 @@ module GSSAPI
43
43
  # Convert a String to a GSSAPI usable buffer (gss_buffer_desc)
44
44
  # @param [String] str the string to convert
45
45
  def import_name(str)
46
- buff_str = LibGSSAPI::GssBufferDesc.new
46
+ buff_str = LibGSSAPI::UnManagedGssBufferDesc.new
47
47
  buff_str.value = str
48
48
  mech = LibGSSAPI::GssOID.gss_c_no_oid
49
49
  #mech = LibGSSAPI.GSS_C_NT_HOSTBASED_SERVICE
@@ -77,10 +77,9 @@ module GSSAPI
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
80
- in_tok = LibGSSAPI::GssBufferDesc.new
80
+ in_tok = LibGSSAPI::UnManagedGssBufferDesc.new
81
81
  in_tok.value = in_token
82
- out_tok = LibGSSAPI::GssBufferDesc.new
83
- out_tok.value = nil
82
+ out_tok = LibGSSAPI::ManagedGssBufferDesc.new
84
83
  ret_flags = FFI::MemoryPointer.new :uint32
85
84
 
86
85
 
@@ -117,10 +116,9 @@ module GSSAPI
117
116
  no_chn_bind = LibGSSAPI::GSS_C_NO_CHANNEL_BINDINGS
118
117
  client = FFI::MemoryPointer.new :pointer # Will hold the initiating client name after the call
119
118
  mech = FFI::MemoryPointer.new :pointer # Will hold the mech being used after the call
120
- in_tok = GSSAPI::LibGSSAPI::GssBufferDesc.new
119
+ in_tok = GSSAPI::LibGSSAPI::UnManagedGssBufferDesc.new
121
120
  in_tok.value = in_token
122
- out_tok = GSSAPI::LibGSSAPI::GssBufferDesc.new
123
- out_tok.value = nil
121
+ out_tok = GSSAPI::LibGSSAPI::ManagedGssBufferDesc.new
124
122
  ret_flags = FFI::MemoryPointer.new :uint32
125
123
 
126
124
  maj_stat = LibGSSAPI.gss_accept_sec_context(min_stat,
@@ -177,11 +175,10 @@ module GSSAPI
177
175
  min_stat = FFI::MemoryPointer.new :uint32
178
176
  conf_req = (encrypt ? 1 : 0)
179
177
  qop_req = GSSAPI::LibGSSAPI::GSS_C_QOP_DEFAULT
180
- in_buff = GSSAPI::LibGSSAPI::GssBufferDesc.new
178
+ in_buff = GSSAPI::LibGSSAPI::UnManagedGssBufferDesc.new
181
179
  in_buff.value = msg
182
180
  conf_state = FFI::MemoryPointer.new :uint32
183
- out_buff = GSSAPI::LibGSSAPI::GssBufferDesc.new
184
- out_buff.value = nil
181
+ out_buff = GSSAPI::LibGSSAPI::ManagedGssBufferDesc.new
185
182
  maj_stat = GSSAPI::LibGSSAPI.gss_wrap(min_stat, @context, conf_req, qop_req, in_buff.pointer, conf_state, out_buff.pointer)
186
183
  raise GssApiError, "Failed to gss_wrap message. Error code: maj: #{maj_stat}, min: #{min_stat.read_int}" if maj_stat != 0
187
184
  out_buff.value
@@ -192,9 +189,9 @@ module GSSAPI
192
189
  # @param [Boolean] encrypted Whether or not this message was encrypted (true) or just signed (false)
193
190
  def unwrap_message(msg, encrypted = true)
194
191
  min_stat = FFI::MemoryPointer.new :uint32
195
- in_buff = GSSAPI::LibGSSAPI::GssBufferDesc.new
192
+ in_buff = GSSAPI::LibGSSAPI::UnManagedGssBufferDesc.new
196
193
  in_buff.value = msg
197
- out_buff = GSSAPI::LibGSSAPI::GssBufferDesc.new
194
+ out_buff = GSSAPI::LibGSSAPI::ManagedGssBufferDesc.new
198
195
  conf_state = FFI::MemoryPointer.new :int
199
196
  conf_state.write_int((encrypted ? 1 : 0))
200
197
  q_op = FFI::MemoryPointer.new :uint32
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gssapi
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.4
5
+ version: 0.1.5
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-02 00:00:00 -06:00
13
+ date: 2011-03-03 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency