ipaccess 1.2.0 → 1.2.2

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.
Files changed (49) hide show
  1. checksums.yaml +5 -13
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.yardopts +2 -0
  5. data/ChangeLog +66 -0
  6. data/Manifest.txt +5 -10
  7. data/README.md +2 -2
  8. data/Rakefile +1 -1
  9. data/docs/HISTORY +11 -0
  10. data/docs/TODO +1 -1
  11. data/docs/yard-tpl/default/fulldoc/html/css/common.css +5 -0
  12. data/examples/open-uri.rb +14 -0
  13. data/examples/telnet.rb +1 -1
  14. data/ipaccess.gemspec +62 -0
  15. data/lib/ipaccess.rb +2 -566
  16. data/lib/ipaccess/arm_sockets.rb +0 -1
  17. data/lib/ipaccess/core.rb +523 -0
  18. data/lib/ipaccess/ghost_doc/ghost_doc.rb +1 -1
  19. data/lib/ipaccess/ghost_doc/ghost_doc_acl.rdoc +54 -0
  20. data/lib/ipaccess/ghost_doc/ghost_doc_net_ftp.rb +35 -19
  21. data/lib/ipaccess/ghost_doc/ghost_doc_net_http.rb +34 -18
  22. data/lib/ipaccess/ghost_doc/ghost_doc_net_smtp.rb +35 -19
  23. data/lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb +35 -19
  24. data/lib/ipaccess/ghost_doc/ghost_doc_patched_usage.rdoc +65 -0
  25. data/lib/ipaccess/ghost_doc/ghost_doc_sockets.rb +353 -125
  26. data/lib/ipaccess/ip_access_check.rb +2 -2
  27. data/lib/ipaccess/ip_access_errors.rb +2 -2
  28. data/lib/ipaccess/ip_access_list.rb +3 -3
  29. data/lib/ipaccess/patches/generic.rb +150 -183
  30. data/lib/ipaccess/patches/net_ftp.rb +1 -2
  31. data/lib/ipaccess/patches/net_http.rb +10 -14
  32. data/lib/ipaccess/patches/net_imap.rb +1 -2
  33. data/lib/ipaccess/patches/net_pop.rb +2 -4
  34. data/lib/ipaccess/patches/net_smtp.rb +2 -4
  35. data/lib/ipaccess/patches/net_telnet.rb +1 -2
  36. data/lib/ipaccess/patches/sockets.rb +67 -69
  37. data/lib/ipaccess/socket.rb +0 -17
  38. metadata +70 -100
  39. metadata.gz.sig +0 -0
  40. data/lib/ipaccess/ghost_doc/ghost_doc_acl.rb +0 -54
  41. data/lib/ipaccess/ghost_doc/ghost_doc_p_blacklist.rb +0 -36
  42. data/lib/ipaccess/ghost_doc/ghost_doc_p_blacklist_e.rb +0 -7
  43. data/lib/ipaccess/ghost_doc/ghost_doc_p_unblacklist.rb +0 -36
  44. data/lib/ipaccess/ghost_doc/ghost_doc_p_unblacklist_e.rb +0 -7
  45. data/lib/ipaccess/ghost_doc/ghost_doc_p_unwhitelist.rb +0 -36
  46. data/lib/ipaccess/ghost_doc/ghost_doc_p_unwhitelist_e.rb +0 -7
  47. data/lib/ipaccess/ghost_doc/ghost_doc_p_whitelist.rb +0 -36
  48. data/lib/ipaccess/ghost_doc/ghost_doc_p_whitelist_e.rb +0 -7
  49. data/lib/ipaccess/ghost_doc/ghost_doc_patched_usage.rb +0 -64
@@ -434,10 +434,10 @@ module IPAccess
434
434
  end
435
435
  return socket
436
436
  end
437
-
437
+
438
438
  # This method checks access for a sockaddr.
439
439
  # It works the same way as check_socket but tests sockaddr structures.
440
-
440
+
441
441
  def check_sockaddr(sockaddr, originator=nil) # :yields: address, rule, list, sockaddr, orig
442
442
  return sockaddr if self.empty?
443
443
  begin
@@ -80,9 +80,9 @@ class IPAccessDenied < SecurityError
80
80
  attr_reader :socket
81
81
 
82
82
  # Access set that was used to check access.
83
-
83
+
84
84
  attr_reader :acl
85
-
85
+
86
86
  # Creates new object. First argument should be
87
87
  # a NetAddr::CIDR object containing address
88
88
  # of denied connection. Second argument should
@@ -368,15 +368,15 @@ module IPAccess
368
368
  # You should avoid passing hostnames as arguments since
369
369
  # DNS is not reliable and responses may change with time,
370
370
  # which may cause security flaws.
371
-
371
+
372
372
  def blacklist(*addresses)
373
373
  addresses.empty? ? self.to_a(:black) : add!(:black, *addresses)
374
374
  end
375
-
375
+
376
376
  alias_method :add_black, :blacklist
377
377
  alias_method :deny, :blacklist
378
378
  alias_method :block, :blacklist
379
-
379
+
380
380
  # This works the same way as blacklist but allows
381
381
  # you to store a reason.
382
382
 
@@ -7,20 +7,6 @@
7
7
  # Modules contained in this file are meant for
8
8
  # patching Ruby classes in order to add
9
9
  # IP access control to them.
10
- #
11
- #--
12
- #
13
- # Copyright (C) 2009 by Paweł Wilk. All Rights Reserved.
14
- #
15
- # This program is free software; you can redistribute it and/or modify
16
- # it under the terms of either: 1) the GNU Lesser General Public License
17
- # as published by the Free Software Foundation; either version 3 of the
18
- # License, or (at your option) any later version; or 2) Ruby's License.
19
- #
20
- # See the file COPYING for complete licensing information.
21
- #
22
- #++
23
- #
24
10
 
25
11
  require 'singleton'
26
12
  require 'ipaccess/ip_access_errors'
@@ -36,13 +22,13 @@ module IPAccess
36
22
  # It is present only when patching engine is loaded.
37
23
 
38
24
  class GlobalClass < Set
39
-
25
+
40
26
  # :stopdoc:
41
-
27
+
42
28
  include Singleton
43
29
 
44
30
  def global?; true end
45
-
31
+
46
32
  def ==(obj)
47
33
  return true if obj.object_id == IPAccess::Set::GlobalSet.instance.object_id
48
34
  super(obj)
@@ -52,23 +38,23 @@ module IPAccess
52
38
  return true if obj.object_id == IPAccess::Set::GlobalSet.instance.object_id
53
39
  super(obj)
54
40
  end
55
-
41
+
56
42
  def to_s
57
43
  "#<IPAccess::Set:Global>"
58
44
  end
59
-
45
+
60
46
  # :startdoc:
61
-
47
+
62
48
  end
63
49
 
64
50
  # This is global access set, used by
65
51
  # default by all socket handling
66
52
  # classes with enabled IP access control.
67
53
  # It is present only when patching engine is loaded.
68
-
54
+
69
55
  Global = GlobalClass.instance
70
56
  Global.name = 'global'
71
-
57
+
72
58
  # This method returns +true+ when
73
59
  # the current instance is not regular IPAccess::Set object
74
60
  # but a reference to the IPAccess::Set.Global,
@@ -77,16 +63,11 @@ module IPAccess
77
63
  #
78
64
  # This method is present only if
79
65
  # patching engine had been loaded.
80
-
66
+
81
67
  def global?; false end
82
-
68
+
83
69
  end # class Set
84
-
85
- # :call-seq:
86
- # arm(klass, acl=nil)<br />
87
- # arm(klass, :opened_on_deny)<br />
88
- # arm(klass, acl, :opened_on_deny)
89
- #
70
+
90
71
  # This special method patches Ruby's standard
91
72
  # library classes and enables IP access control
92
73
  # for them. Instances of such altered classes
@@ -95,10 +76,10 @@ module IPAccess
95
76
  # to manipulate access rules. It is also
96
77
  # able to patch single instance of supported
97
78
  # classes.
98
- #
79
+ #
99
80
  # This method returns object that has
100
81
  # been patched.
101
- #
82
+ #
102
83
  # ==== Supported classes
103
84
  #
104
85
  # Currently supported classes are:
@@ -110,13 +91,13 @@ module IPAccess
110
91
  # – Net::POP3,
111
92
  # – Net::IMAP,
112
93
  # – Net::SMTP.
113
- #
94
+ #
114
95
  # ==== Patching classes
115
96
  #
116
97
  # Passed argument may be a class object,
117
98
  # a string representation of a class object
118
99
  # or a symbol representing a class object.
119
- #
100
+ #
120
101
  # ==== Patching single instances
121
102
  #
122
103
  # Passed argument may be an instance of
@@ -135,53 +116,55 @@ module IPAccess
135
116
  # argument.
136
117
  #
137
118
  # === Examples
138
- #
119
+ #
139
120
  # ==== Example 1 – sockets
140
121
  #
141
- # require 'ipaccess/socket' # load sockets subsystem and IPAccess.arm method
122
+ # require 'ipaccess/socket' # load sockets subsystem and IPAccess.arm method
142
123
  #
143
- # IPAccess.arm TCPSocket # arm TCPSocket class
144
- # IPAccess::Set::Global.output.blacklist 'randomseed.pl' # add host to black list of the global set
145
- # TCPSocket.new('randomseed.pl', 80) # try to connect
124
+ # IPAccess.arm TCPSocket # arm TCPSocket class
125
+ # IPAccess::Set::Global.output.blacklist 'randomseed.pl' # add host to black list of the global set
126
+ # TCPSocket.new('randomseed.pl', 80) # try to connect
146
127
  #
147
128
  # ==== Example 2 – HTTP
148
129
  #
149
- # require 'ipaccess/net/http' # load net/http subsystem and IPAccess.arm method
130
+ # require 'ipaccess/net/http' # load net/http subsystem and IPAccess.arm method
150
131
  #
151
- # IPAccess.arm Net::HTTP # arm TCPSocket class
152
- # IPAccess::Set::Global.output.blacklist 'randomseed.pl' # add host to black list of the global set
153
- # Net::HTTP.get_print('randomseed.pl', '/i.html') # try to connect
132
+ # IPAccess.arm Net::HTTP # arm TCPSocket class
133
+ # IPAccess::Set::Global.output.blacklist 'randomseed.pl' # add host to black list of the global set
134
+ # Net::HTTP.get_print('randomseed.pl', '/i.html') # try to connect
154
135
  #
155
136
  # ==== Example 3 – single network object
156
137
  #
157
- # require 'ipaccess/net/telnet' # load Net::Telnet version and IPAccess.arm method
138
+ # require 'ipaccess/net/telnet' # load Net::Telnet version and IPAccess.arm method
158
139
  #
159
140
  # opts = {}
160
141
  # opts["Host"] = 'randomseed.pl'
161
142
  # opts["Port"] = '80'
162
143
  #
163
- # t = Net::Telnet.new(opts) # try to connect to remote host
144
+ # t = Net::Telnet.new(opts) # try to connect to remote host
164
145
  #
165
- # acl = IPAccess::Set.new # create custom access set
166
- # acl.output.blacklist 'randomseed.pl' # blacklist host
167
- # IPAccess.arm t, acl # arm Telnet object and pass optional ACL
168
-
146
+ # acl = IPAccess::Set.new # create custom access set
147
+ # acl.output.blacklist 'randomseed.pl' # blacklist host
148
+ # IPAccess.arm t, acl # arm Telnet object and pass optional ACL
149
+ #
150
+ # @overload arm(klass, acl=nil)
151
+ # @overload arm(klass, :opened_on_deny)
152
+ # @overload arm(klass, acl, :opened_on_deny)
153
+
169
154
  def self.arm(*args)
170
- cod = args.delete(:opened_on_deny).nil? ? true : false
155
+ cod = args.delete(:opened_on_deny).nil?
171
156
  klass, acl = *args
172
157
  singleton_obj = nil
173
158
  if klass.is_a?(Class) # regular class
174
- klass_name = klass.name
175
- elsif (klass.is_a?(Symbol) || klass.is_a?(String))
159
+ klass_name = klass.name
160
+ elsif klass.is_a?(Symbol) || klass.is_a?(String)
176
161
  klass_name = klass.to_s
177
162
  if klass.name.downcase == "sockets" # just a bunch of sockets
178
163
  require 'ipaccess/arm_sockets'
179
164
  return
180
165
  else # regular class as a string or symbol
181
166
  klass = Kernel
182
- klass_name.to_s.split('::').each do |k|
183
- klass = klass.const_get(k)
184
- end
167
+ klass_name.to_s.split('::').each { |k| klass = klass.const_get(k) }
185
168
  end
186
169
  else # regular object (will patch singleton of this object)
187
170
  klass_name = klass.class.name
@@ -190,25 +173,23 @@ module IPAccess
190
173
  end
191
174
  begin
192
175
  patch_klass = IPAccess::Patches
193
- klass_name.split('::').each do |k|
194
- patch_klass = patch_klass.const_get(k)
195
- end
176
+ klass_name.split('::').each { |k| patch_klass = patch_klass.const_get(k, false) }
196
177
  rescue NameError
197
- raise ArgumentError, "cannot enable IP access control for class #{klass_name}"
178
+ raise ArgumentError, "Cannot enable IP access control for class #{klass_name}"
198
179
  end
199
180
  klass.__send__(:include, patch_klass)
200
- singleton_obj.__send__(:__ipa_singleton_hook, acl, cod) unless singleton_obj.nil?
181
+ singleton_obj.__send__(:__ipa_singleton_hook, acl, cod) unless singleton_obj.nil? # early initial check
201
182
  return klass
202
183
  end
203
-
184
+
204
185
  # :stopdoc:
205
-
186
+
206
187
  # This module patches network classes
207
188
  # to enforce IP access control for them. Each patched
208
189
  # class has the acl member, which is an IPAccess::Set object.
209
190
 
210
191
  module Patches
211
-
192
+
212
193
  # This class is a proxy that raises an exception when
213
194
  # any method other than defined in Object class is called.
214
195
  # It behaves like NilClass. Do not use this class, use
@@ -221,7 +202,7 @@ module IPAccess
221
202
  # imitate nil
222
203
  def nil?; true end
223
204
 
224
- # This method returns +true+ if current object is IPAccess::Set.Global.
205
+ # This method returns +true+ if the current object is IPAccess::Set.Global.
225
206
  # Otherwise it returns +false+.
226
207
  def global?; true end
227
208
 
@@ -244,7 +225,7 @@ module IPAccess
244
225
  # imitate nil even more and disallow direct ACL modifications
245
226
  def method_missing(name, *args)
246
227
  return nil.method(name).call(*args) if nil.respond_to?(name)
247
- raise ArgumentError, "cannot access global set from object's scope, use IPAccess::Set::Global"
228
+ raise ArgumentError, "Cannot access global set from object's scope, use IPAccess::Set::Global"
248
229
  end
249
230
 
250
231
  end # class IPAccess::Set.GlobalSet
@@ -252,19 +233,19 @@ module IPAccess
252
233
  # The ACL module contains methods
253
234
  # that are present in all network
254
235
  # objects with IP access control enabled.
255
-
236
+
256
237
  module ACL
257
238
 
258
239
  # This method is used to safely
259
240
  # pass an eventual exception
260
241
  # and fill its useables field with a current
261
242
  # object.
262
-
243
+
263
244
  def __ipa_wrap_socket_call(*args, &block)
264
245
  IPAccess.take_care(self, *args, &block)
265
246
  end
266
247
  protected :__ipa_wrap_socket_call
267
-
248
+
268
249
  # This method enables usage of internal IP access list for object.
269
250
  # If argument is IPAccess::Set object then it is used.
270
251
  #
@@ -273,10 +254,10 @@ module IPAccess
273
254
  # socket.acl = :global # use global access set
274
255
  # socket.acl = :private # create and use individual access set
275
256
  # socket.acl = IPAccess::Set.new # use external (shared) access set
276
-
257
+
277
258
  def acl=(access_set)
278
- new_acl = nil
279
- prev_acl = @acl
259
+ new_acl = false
260
+ prev_acl = @acl
280
261
  if access_set.is_a?(Symbol)
281
262
  case access_set
282
263
  when :global
@@ -284,28 +265,24 @@ module IPAccess
284
265
  when :private
285
266
  new_acl = IPAccess::Set.new
286
267
  else
287
- raise ArgumentError, "bad access list selector, use: :global or :private"
268
+ raise ArgumentError, "Bad access list selector, use: :global or :private"
288
269
  end
289
270
  elsif access_set.is_a?(IPAccess::Set)
290
- if access_set == IPAccess::Set::Global
291
- new_acl = IPAccess::Set::GlobalSet.instance
292
- else
293
- new_acl = access_set
294
- end
271
+ new_acl = ( access_set == IPAccess::Set::Global ? IPAccess::Set::GlobalSet.instance : access_set )
295
272
  elsif access_set.nil?
296
273
  new_acl = IPAccess::Set::GlobalSet.instance
297
274
  else
298
- raise ArgumentError, "bad access list"
275
+ raise ArgumentError, "Bad access list"
299
276
  end
300
- unless (new_acl.nil? || prev_acl.object_id == new_acl.object_id)
277
+ unless (new_acl === false || prev_acl.object_id == new_acl.object_id)
301
278
  @acl = new_acl
302
279
  self.acl_recheck if self.respond_to?(:acl_recheck)
303
280
  end
304
281
  end
305
-
282
+
306
283
  # This method returns +true+ if the given object can be used to initialize ACL.
307
284
  # Otherwise it returns +false+.
308
-
285
+
309
286
  def IPAccess.valid_acl?(obj)
310
287
  if obj.is_a?(Symbol)
311
288
  return true if (obj == :global || obj == :private)
@@ -314,14 +291,14 @@ module IPAccess
314
291
  end
315
292
  return false
316
293
  end
317
-
294
+
318
295
  # This method returns +true+ if the given object can be used to initialize ACL.
319
296
  # Otherwise it returns +false+.
320
-
297
+
321
298
  def valid_acl?(obj)
322
299
  IPAccess.valid_acl?(obj)
323
300
  end
324
-
301
+
325
302
  # This method should be called each time the access set related to an object
326
303
  # is changed and there is a need to validate remote peer again, since it might be
327
304
  # blacklisted.
@@ -329,11 +306,11 @@ module IPAccess
329
306
  # Each class that patches Ruby's network class should redefine this method
330
307
  # and call it in a proper place (e.g. from hook executed when singleton methods
331
308
  # are added to network object).
332
-
309
+
333
310
  def acl_recheck
334
311
  ;
335
312
  end
336
-
313
+
337
314
  # This method return current access set for an object.
338
315
  #
339
316
  # Ifaccess set (@acl) is somehow set to +nil+
@@ -341,26 +318,22 @@ module IPAccess
341
318
  # (which is internal singleton used to mark that @acl should
342
319
  # point to the global set) it will return a reference
343
320
  # to the global access set IPAccess::Set.Global.
344
-
321
+
345
322
  def real_acl
346
323
  @acl.nil? ? IPAccess::Set::Global : @acl
347
324
  end
348
325
  private :real_acl
349
-
326
+
350
327
  attr_reader :acl
351
328
  alias_method :access=, :acl=
352
- alias_method :access, :acl
353
-
329
+ alias_method :access, :acl
330
+
354
331
  # This method returns default access list indicator
355
332
  # used by protected object; usually +:input+ or
356
333
  # +:output+.
357
-
334
+
358
335
  def default_list; :output end
359
-
360
- # :call-seq:
361
- # whitelist(list, *addresses)
362
- # whitelist(*addresses)
363
- #
336
+
364
337
  # This method whitelists IP address(-es) in
365
338
  # the input or output access list selected
366
339
  # by the *list* argument (+:input+ or +:output+).
@@ -380,15 +353,18 @@ module IPAccess
380
353
  # whitelist! instead.
381
354
  #
382
355
  # === Revalidation
383
- #
356
+ #
384
357
  # After modyfing access set current connection
385
358
  # is validated again to avoid access leaks.
386
359
  #
387
360
  # === DNS Warning
388
- #
361
+ #
389
362
  # You should avoid passing hostnames as arguments since
390
363
  # DNS is not reliable and responses may change with time,
391
364
  # which may cause security flaws.
365
+ #
366
+ # @overload whitelist(*addresses)
367
+ # @overload whitelist(list, *addresses)
392
368
 
393
369
  def whitelist(*addresses)
394
370
  aclist = ( addresses.first.is_a?(Symbol) && [:input,:output].include?(addresses.first) ) ? addresses.shift : self.default_list
@@ -396,25 +372,21 @@ module IPAccess
396
372
  self.acl_recheck
397
373
  return r
398
374
  end
399
-
375
+
400
376
  alias_method :add_white, :whitelist
401
377
  alias_method :allow, :whitelist
402
378
  alias_method :permit, :whitelist
403
-
379
+
404
380
  # This method works like whitelist but allows
405
381
  # to set reason.
406
-
382
+
407
383
  def whitelist_reasonable(reason, *addresses)
408
384
  aclist = ( addresses.first.is_a?(Symbol) && [:input,:output].include?(addresses.first) ) ? addresses.shift : self.default_list
409
385
  r = @acl.send(aclist).whitelist_reasonable(reason, *addresses)
410
386
  self.acl_recheck
411
387
  return r
412
388
  end
413
-
414
- # :call-seq:
415
- # whitelist!(list, *addresses)
416
- # whitelist!(*addresses)
417
- #
389
+
418
390
  # This method whitelists IP address(-es) in
419
391
  # the input or output access list selected
420
392
  # by the *list* argument (+:input+ or +:output+).
@@ -432,15 +404,18 @@ module IPAccess
432
404
  # even if the global access set is used by object.
433
405
  #
434
406
  # === Revalidation
435
- #
407
+ #
436
408
  # After modyfing access set current connection
437
409
  # is validated again to avoid access leaks.
438
410
  #
439
411
  # === DNS Warning
440
- #
412
+ #
441
413
  # You should avoid passing hostnames as arguments since
442
414
  # DNS is not reliable and responses may change with time,
443
415
  # which may cause security flaws.
416
+ #
417
+ # @overload whitelist!(*addresses)
418
+ # @overload whitelist!(list, *addresses)
444
419
 
445
420
  def whitelist!(*addresses)
446
421
  aclist = ( addresses.first.is_a?(Symbol) && [:input,:output].include?(addresses.first) ) ? addresses.shift : self.default_list
@@ -448,7 +423,7 @@ module IPAccess
448
423
  self.acl_recheck
449
424
  return r
450
425
  end
451
-
426
+
452
427
  alias_method :add_white!, :whitelist!
453
428
  alias_method :allow!, :whitelist!
454
429
  alias_method :permit!, :whitelist!
@@ -462,11 +437,7 @@ module IPAccess
462
437
  self.acl_recheck
463
438
  return r
464
439
  end
465
-
466
- # :call-seq:
467
- # unwhitelist(list, *addresses)
468
- # unwhitelist(*addresses)
469
- #
440
+
470
441
  # This method removes whitelisted IP address(-es)
471
442
  # from the input or output access list selected
472
443
  # by the *list* argument (+:input+ or +:output+).
@@ -486,32 +457,31 @@ module IPAccess
486
457
  # unwhitelist! instead.
487
458
  #
488
459
  # === Revalidation
489
- #
460
+ #
490
461
  # After modyfing access set current connection
491
462
  # is validated again to avoid access leaks.
492
463
  #
493
464
  # === DNS Warning
494
- #
465
+ #
495
466
  # You should avoid passing hostnames as arguments since
496
467
  # DNS is not reliable and responses may change with time,
497
468
  # which may cause security flaws.
498
-
469
+ #
470
+ # @overload unwhitelist(*addresses)
471
+ # @overload unwhitelist(list, *addresses)
472
+
499
473
  def unwhitelist(*addresses)
500
474
  aclist = ( addresses.first.is_a?(Symbol) && [:input,:output].include?(addresses.first) ) ? addresses.shift : self.default_list
501
475
  r = @acl.send(aclist).unwhitelist(*addresses)
502
476
  self.acl_recheck
503
477
  return r
504
478
  end
505
-
479
+
506
480
  alias_method :unwhite, :unwhitelist
507
481
  alias_method :del_white, :unwhitelist
508
482
  alias_method :unallow, :unwhitelist
509
483
  alias_method :unpermit, :unwhitelist
510
-
511
- # :call-seq:
512
- # unwhitelist!(list, *addresses)
513
- # unwhitelist!(*addresses)
514
- #
484
+
515
485
  # This method removes whitelisted IP address(-es)
516
486
  # from the input or output access list selected
517
487
  # by the *list* argument (+:input+ or +:output+).
@@ -529,32 +499,31 @@ module IPAccess
529
499
  # even if the global access set is used by object.
530
500
  #
531
501
  # === Revalidation
532
- #
502
+ #
533
503
  # After modyfing access set current connection
534
504
  # is validated again to avoid access leaks.
535
505
  #
536
506
  # === DNS Warning
537
- #
507
+ #
538
508
  # You should avoid passing hostnames as arguments since
539
509
  # DNS is not reliable and responses may change with time,
540
510
  # which may cause security flaws.
541
-
511
+ #
512
+ # @overload unwhitelist!(*addresses)
513
+ # @overload unwhitelist!(list, *addresses)
514
+
542
515
  def unwhitelist!(*addresses)
543
516
  aclist = ( addresses.first.is_a?(Symbol) && [:input,:output].include?(addresses.first) ) ? addresses.shift : self.default_list
544
517
  r = real_acl.send(aclist).unwhitelist(*addresses)
545
518
  self.acl_recheck
546
519
  return r
547
520
  end
548
-
521
+
549
522
  alias_method :unwhite!, :unwhitelist!
550
523
  alias_method :del_white!, :unwhitelist!
551
524
  alias_method :unallow!, :unwhitelist!
552
525
  alias_method :unpermit!, :unwhitelist!
553
-
554
- # :call-seq:
555
- # blacklist(list, *addresses)
556
- # blacklist(*addresses)
557
- #
526
+
558
527
  # This method blacklists IP address(-es) in
559
528
  # the input or output access list selected
560
529
  # by the *list* argument (+:input+ or +:output+).
@@ -574,41 +543,40 @@ module IPAccess
574
543
  # blacklist! instead.
575
544
  #
576
545
  # === Revalidation
577
- #
546
+ #
578
547
  # After modyfing access set current connection
579
548
  # is validated again to avoid access leaks.
580
549
  #
581
550
  # === DNS Warning
582
- #
551
+ #
583
552
  # You should avoid passing hostnames as arguments since
584
553
  # DNS is not reliable and responses may change with time,
585
554
  # which may cause security flaws.
586
-
555
+ #
556
+ # @overload blacklist(*addresses)
557
+ # @overload blacklist(list, *addresses)
558
+
587
559
  def blacklist(*addresses)
588
560
  aclist = ( addresses.first.is_a?(Symbol) && [:input,:output].include?(addresses.first) ) ? addresses.shift : self.default_list
589
561
  r = @acl.send(aclist).blacklist(*addresses)
590
562
  self.acl_recheck
591
563
  return r
592
564
  end
593
-
565
+
594
566
  alias_method :add_black, :blacklist
595
567
  alias_method :deny, :blacklist
596
568
  alias_method :block, :blacklist
597
-
569
+
598
570
  # This method works like blacklist but allows to
599
571
  # set reason.
600
-
572
+
601
573
  def blacklist_reasonable(reason, *addresses)
602
574
  aclist = ( addresses.first.is_a?(Symbol) && [:input,:output].include?(addresses.first) ) ? addresses.shift : self.default_list
603
575
  r = @acl.send(aclist).blacklist_reasonable(reason, *addresses)
604
576
  self.acl_recheck
605
577
  return r
606
578
  end
607
-
608
- # :call-seq:
609
- # blacklist!(list, *addresses)
610
- # blacklist!(*addresses)
611
- #
579
+
612
580
  # This method blacklists IP address(-es) in
613
581
  # the input or output access list selected
614
582
  # by the *list* argument (+:input+ or +:output+).
@@ -626,41 +594,40 @@ module IPAccess
626
594
  # even if the global access set is used by object.
627
595
  #
628
596
  # === Revalidation
629
- #
597
+ #
630
598
  # After modyfing access set current connection
631
599
  # is validated again to avoid access leaks.
632
600
  #
633
601
  # === DNS Warning
634
- #
602
+ #
635
603
  # You should avoid passing hostnames as arguments since
636
604
  # DNS is not reliable and responses may change with time,
637
605
  # which may cause security flaws.
638
-
606
+ #
607
+ # @overload blacklist!(*addresses)
608
+ # @overload blacklist!(list, *addresses)
609
+
639
610
  def blacklist!(*addresses)
640
611
  aclist = ( addresses.first.is_a?(Symbol) && [:input,:output].include?(addresses.first) ) ? addresses.shift : self.default_list
641
612
  r = real_acl.send(aclist).blacklist(*addresses)
642
613
  self.acl_recheck
643
614
  return r
644
615
  end
645
-
616
+
646
617
  alias_method :add_black!, :blacklist!
647
618
  alias_method :deny!, :blacklist!
648
619
  alias_method :block!, :blacklist!
649
620
 
650
621
  # This method works like blacklist! but allows
651
622
  # to set reason.
652
-
623
+
653
624
  def blacklist_reasonable!(reason, *addresses)
654
625
  aclist = ( addresses.first.is_a?(Symbol) && [:input,:output].include?(addresses.first) ) ? addresses.shift : self.default_list
655
626
  r = real_acl.send(aclist).blacklist(reason, *addresses)
656
627
  self.acl_recheck
657
628
  return r
658
629
  end
659
-
660
- # :call-seq:
661
- # unblacklist(list, *addresses)
662
- # unblacklist(*addresses)
663
- #
630
+
664
631
  # This method removes blacklisted IP address(-es)
665
632
  # from the input or output access list selected
666
633
  # by the *list* argument (+:input+ or +:output+).
@@ -680,32 +647,31 @@ module IPAccess
680
647
  # unwhitelist! instead.
681
648
  #
682
649
  # === Revalidation
683
- #
650
+ #
684
651
  # After modyfing access set current connection
685
652
  # is validated again to avoid access leaks.
686
653
  #
687
654
  # === DNS Warning
688
- #
655
+ #
689
656
  # You should avoid passing hostnames as arguments since
690
657
  # DNS is not reliable and responses may change with time,
691
658
  # which may cause security flaws.
692
-
659
+ #
660
+ # @overload unblacklist(*addresses)
661
+ # @overload unblacklist(list, *addresses)
662
+
693
663
  def unblacklist(*addresses)
694
664
  aclist = ( addresses.first.is_a?(Symbol) && [:input,:output].include?(addresses.first) ) ? addresses.shift : self.default_list
695
665
  r = @acl.send(aclist).unblacklist(*addresses)
696
666
  self.acl_recheck
697
667
  return r
698
668
  end
699
-
669
+
700
670
  alias_method :unblack, :unblacklist
701
671
  alias_method :undeny, :unblacklist
702
672
  alias_method :unblock, :unblacklist
703
673
  alias_method :del_black, :unblacklist
704
-
705
- # :call-seq:
706
- # unblacklist!(list, *addresses)
707
- # unblacklist!(*addresses)
708
- #
674
+
709
675
  # This method removes blacklisted IP address(-es)
710
676
  # from the input or output access list selected
711
677
  # by the *list* argument (+:input+ or +:output+).
@@ -723,79 +689,82 @@ module IPAccess
723
689
  # even if the global access set is used by object.
724
690
  #
725
691
  # === Revalidation
726
- #
692
+ #
727
693
  # After modyfing access set current connection
728
694
  # is validated again to avoid access leaks.
729
695
  #
730
696
  # === DNS Warning
731
- #
697
+ #
732
698
  # You should avoid passing hostnames as arguments since
733
699
  # DNS is not reliable and responses may change with time,
734
700
  # which may cause security flaws.
735
-
701
+ #
702
+ # @overload unblacklist!(*addresses)
703
+ # @overload unblacklist!(list, *addresses)
704
+
736
705
  def unblacklist!(*addresses)
737
706
  aclist = ( addresses.first.is_a?(Symbol) && [:input,:output].include?(addresses.first) ) ? addresses.shift : self.default_list
738
707
  r = real_acl.send(aclist).unblacklist(*addresses)
739
708
  self.acl_recheck
740
709
  return r
741
710
  end
742
-
711
+
743
712
  alias_method :unblack!, :unblacklist!
744
713
  alias_method :undeny!, :unblacklist!
745
714
  alias_method :unblock!, :unblacklist!
746
715
  alias_method :del_black!, :unblacklist!
747
-
716
+
748
717
  # Setting it to +false+ disables closing connection
749
718
  # when raising access denied exception
750
-
719
+
751
720
  attr_accessor :opened_on_deny
752
-
721
+
753
722
  # Setting it to +true+ disables closing connection
754
723
  # when raising access denied exception
755
-
724
+
756
725
  def close_on_deny=(x)
757
726
  self.open_on_deny = !x
758
727
  end
759
-
728
+
760
729
  def close_on_deny
761
730
  not self.open_on_deny
762
731
  end
763
-
732
+
764
733
  # This method is universal wrapper for
765
734
  # closing connection. Classes should
766
735
  # override it.
767
-
736
+
768
737
  def terminate
769
738
  self.close unless self.closed?
770
739
  end
771
-
740
+
772
741
  # This method will try to close
773
- # session/connection for network object
742
+ # session/connection for a network object
774
743
  # if +open_on_deny+ member is set to +false+
775
-
744
+
776
745
  def try_terminate
777
746
  terminate unless @opened_on_deny
778
747
  return nil
779
748
  end
780
749
  private :try_terminate
781
-
750
+
782
751
  # helper for dropping unwanted connections
783
752
  def try_terminate_subsocket(sock)
784
753
  sock.close unless (@opened_on_deny || sock.closed?)
785
754
  return nil
786
755
  end
787
756
  private :try_terminate_subsocket
788
-
757
+
789
758
  # This method will be called when
790
759
  # instance is patched.
791
-
792
- def __ipa_singleton_hook(acl=nil, open_on_deny=false)
760
+
761
+ def __ipa_singleton_hook(acl = nil, open_on_deny = false)
793
762
  @opened_on_deny = open_on_deny
794
763
  acl = @options["ACL"] if (acl.nil? && instance_variable_defined?(:@options) && @options.respond_to?(:has_key?))
795
764
  self.acl = acl
796
765
  end
797
766
  private :__ipa_singleton_hook
798
-
767
+
799
768
  end # module ACL
800
769
 
801
770
  end # module Patches
@@ -803,5 +772,3 @@ module IPAccess
803
772
  # :startdoc:
804
773
 
805
774
  end # module IPAccess
806
-
807
-