ruby-activeldap-debug 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,8 @@
1
1
  # === ActiveLDAP - an OO-interface to LDAP objects inspired by ActiveRecord
2
2
  # Author: Will Drewry <will@alum.bu.edu>
3
3
  # License: See LICENSE and COPYING.txt
4
- # Copyright 2004 Will Drewry <will@alum.bu.edu>
4
+ # Copyright 2004-2006 Will Drewry <will@alum.bu.edu>
5
+ # Some portions Copyright 2006 Google Inc
5
6
  #
6
7
  # == Summary
7
8
  # ActiveLDAP lets you read and update LDAP entries in a completely object
@@ -347,6 +348,12 @@ module ActiveLDAP
347
348
  retry if Base.reconnect()
348
349
  # Do nothing on failure
349
350
  @@logger.debug "No matches for #{config[:filter]} and attrs #{config[:attrs]}"
351
+ rescue => detail
352
+ if LDAP::err2exception(@@conn.err)[0] == LDAP::ServerDown
353
+ @@logger.debug("Failed to write: #{entry}")
354
+ retry if Base.reconnect()
355
+ end
356
+ raise detail
350
357
  end
351
358
  return values
352
359
  end
@@ -407,6 +414,12 @@ module ActiveLDAP
407
414
 
408
415
  # Do nothing on failure
409
416
  @@logger.debug "no matches for #{attr}=#{val}"
417
+ rescue => detail
418
+ if LDAP::err2exception(@@conn.err)[0] == LDAP::ServerDown
419
+ @@logger.debug("Failed to write: #{entry}")
420
+ retry if Base.reconnect()
421
+ end
422
+ raise detail
410
423
  end
411
424
  return nil
412
425
  end
@@ -464,6 +477,12 @@ module ActiveLDAP
464
477
 
465
478
  # Do nothing on failure
466
479
  @@logger.debug "no matches for #{attr}=#{val}"
480
+ rescue => detail
481
+ if LDAP::err2exception(@@conn.err)[0] == LDAP::ServerDown
482
+ @@logger.debug("Failed to write: #{entry}")
483
+ retry if Base.reconnect()
484
+ end
485
+ raise detail
467
486
  end
468
487
  return matches
469
488
  end
@@ -714,6 +733,10 @@ module ActiveLDAP
714
733
  retry if Base.reconnect()
715
734
  raise DeleteError, "Failed to delete LDAP entry: '#{@dn}'"
716
735
  rescue LDAP::ResultError => detail
736
+ if LDAP::err2exception(@@conn.err)[0] == LDAP::ServerDown
737
+ @@logger.debug("Failed to write: #{entry}")
738
+ retry if Base.reconnect()
739
+ end
717
740
  raise DeleteError, "Failed to delete LDAP entry: '#{@dn}'"
718
741
  end
719
742
  end
@@ -796,6 +819,8 @@ module ActiveLDAP
796
819
  name = @attr_methods[name]
797
820
  name = pair[0].split(/;/)[0] if name.nil? # for objectClass, or removed vals
798
821
  value = data[name+suffix]
822
+ # If it doesn't exist, don't freak out.
823
+ value = [] if value.nil?
799
824
 
800
825
  # Detect subtypes and account for them
801
826
  binary = LDAP::LDAP_MOD_BVALUES if Base.schema.binary? name
@@ -827,6 +852,8 @@ module ActiveLDAP
827
852
  name = @attr_methods[name]
828
853
  name = pair[0].split(/;/)[0] if name.nil? # for obj class or removed vals
829
854
  value = pair[1]
855
+ # Make sure to change this to an Array if there was mistake earlier.
856
+ value = [] if value.nil?
830
857
 
831
858
  if not replaceable.member? name+suffix
832
859
  # Detect subtypes and account for them
@@ -843,11 +870,17 @@ module ActiveLDAP
843
870
  @@conn.modify(@dn, entry)
844
871
  @@logger.debug("#write: modify successful")
845
872
  rescue RuntimeError => detail
846
- #todo# check for 'no message' when retrying
873
+ #todo# check for SERVER_DOWN
847
874
  # the connection may have gone stale. let's reconnect and retry.
848
875
  retry if Base.reconnect()
849
876
  raise WriteError, "Could not update LDAP entry: #{detail}"
850
877
  rescue => detail
878
+ @@logger.debug(LDAP::err2exception(@@conn.err).inspect)
879
+ if LDAP::err2exception(@@conn.err)[0] == LDAP::ServerDown
880
+ @@logger.debug("Failed to write: #{entry}")
881
+ retry if Base.reconnect()
882
+ end
883
+ @@logger.debug("Failed to write: #{entry}")
851
884
  raise WriteError, "Could not update LDAP entry: #{detail}"
852
885
  end
853
886
  else # add everything!
@@ -880,6 +913,10 @@ module ActiveLDAP
880
913
  retry if Base.reconnect()
881
914
  raise WriteError, "Could not add LDAP entry[#{Base.connection.err2string(Base.connection.err)}]: #{detail}"
882
915
  rescue LDAP::ResultError => detail
916
+ if LDAP::err2exception(@@conn.err)[0] == LDAP::ServerDown
917
+ @@logger.debug("Failed to write: #{entry}")
918
+ retry if Base.reconnect()
919
+ end
883
920
  raise WriteError, "Could not add LDAP entry[#{Base.connection.err2string(Base.connection.err)}]: #{detail}"
884
921
  end
885
922
  end
@@ -1347,8 +1384,21 @@ module ActiveLDAP
1347
1384
  raise AttributeAssignmentError, 'cannot modify the DN attribute value'
1348
1385
  end
1349
1386
 
1387
+ # Enforce LDAP-pleasing values
1388
+ @@logger.debug("value = #{value.inspect}, value.class = #{value.class}")
1389
+ real_value = value
1390
+ # Squash empty values
1391
+ if value.class == Array
1392
+ real_value = value.collect {|c| if c == ''; []; else c; end }.flatten
1393
+ end
1394
+ real_value = [] if real_value.nil?
1395
+ real_value = [] if real_value == ''
1396
+ real_value = [real_value] if real_value.class == String
1397
+ real_value = [real_value.to_s] if real_value.class == Fixnum
1398
+ # NOTE: Hashes are allowed for subtyping.
1399
+
1350
1400
  # Assign the value
1351
- @data[attr] = value
1401
+ @data[attr] = real_value
1352
1402
 
1353
1403
  # Return the passed in value
1354
1404
  @@logger.debug("stub: exitting attribute_method=")
@@ -1,25 +1,104 @@
1
1
  # Extensions to Rubu/LDAP to make ActiveLDAP behave better
2
2
  #
3
+ # Copyright 2006 Will Drewry <will@alum.bu.edu>
4
+ # Some portions Copyright 2006 Google Inc
3
5
 
4
6
 
5
7
 
6
8
  module LDAP
7
- # Creates useful exceptions from err2string output
9
+ ERRORS = [
10
+ "LDAP_SUCCESS",
11
+ "LDAP_OPERATIONS_ERROR",
12
+ "LDAP_PROTOCOL_ERROR",
13
+ "LDAP_TIMELIMIT_EXCEEDED",
14
+ "LDAP_SIZELIMIT_EXCEEDED",
15
+ "LDAP_COMPARE_FALSE",
16
+ "LDAP_COMPARE_TRUE",
17
+ "LDAP_STRONG_AUTH_NOT_SUPPORTED",
18
+ "LDAP_AUTH_METHOD_NOT_SUPPORTED",
19
+ "LDAP_STRONG_AUTH_REQUIRED",
20
+ "LDAP_REFERRAL",
21
+ "LDAP_ADMINLIMIT_EXCEEDED",
22
+ "LDAP_UNAVAILABLE_CRITICAL_EXTENSION",
23
+ "LDAP_CONFIDENTIALITY_REQUIRED",
24
+ "LDAP_SASL_BIND_IN_PROGRESS",
25
+ "LDAP_PARTIAL_RESULTS",
26
+ "LDAP_NO_SUCH_ATTRIBUTE",
27
+ "LDAP_UNDEFINED_TYPE",
28
+ "LDAP_INAPPROPRIATE_MATCHING",
29
+ "LDAP_CONSTRAINT_VIOLATION",
30
+ "LDAP_TYPE_OR_VALUE_EXISTS",
31
+ "LDAP_INVALID_SYNTAX",
32
+ "LDAP_NO_SUCH_OBJECT",
33
+ "LDAP_ALIAS_PROBLEM",
34
+ "LDAP_INVALID_DN_SYNTAX",
35
+ "LDAP_IS_LEAF",
36
+ "LDAP_ALIAS_DEREF_PROBLEM",
37
+ "LDAP_INAPPROPRIATE_AUTH",
38
+ "LDAP_INVALID_CREDENTIALS",
39
+ "LDAP_INSUFFICIENT_ACCESS",
40
+ "LDAP_BUSY",
41
+ "LDAP_UNAVAILABLE",
42
+ "LDAP_UNWILLING_TO_PERFORM",
43
+ "LDAP_LOOP_DETECT",
44
+ "LDAP_NAMING_VIOLATION",
45
+ "LDAP_OBJECT_CLASS_VIOLATION",
46
+ "LDAP_NOT_ALLOWED_ON_NONLEAF",
47
+ "LDAP_NOT_ALLOWED_ON_RDN",
48
+ "LDAP_ALREADY_EXISTS",
49
+ "LDAP_NO_OBJECT_CLASS_MODS",
50
+ "LDAP_RESULTS_TOO_LARGE",
51
+ "LDAP_OTHER",
52
+ "LDAP_SERVER_DOWN",
53
+ "LDAP_LOCAL_ERROR",
54
+ "LDAP_ENCODING_ERROR",
55
+ "LDAP_DECODING_ERROR",
56
+ "LDAP_TIMEOUT",
57
+ "LDAP_AUTH_UNKNOWN",
58
+ "LDAP_FILTER_ERROR",
59
+ "LDAP_USER_CANCELLED",
60
+ "LDAP_PARAM_ERROR",
61
+ "LDAP_NO_MEMORY",
62
+ "LDAP_CONNECT_ERROR"
63
+ ]
64
+ attr_reader :error_map
65
+ # Calls err2exception() with 1...100 to
66
+ # pregenerate all the constants for errors.
67
+ # TODO: look at other support LDAP SDKs for weirdness
68
+ def LDAP::generate_err2exceptions()
69
+ hash = {}
70
+ ERRORS.each do |err|
71
+ begin
72
+ val = LDAP.const_get(err)
73
+ # Make name into a exception
74
+ exc = err.gsub(/^LDAP_/, '')
75
+ exc = exc.split('_').collect {|w| w.capitalize }.join('')
76
+ # Doesn't exist :-)
77
+ LDAP.module_eval(<<-end_module_eval)
78
+ class #{exc} < LDAP::ResultError
79
+ end
80
+ end_module_eval
81
+ hash[val] = exc
82
+ rescue NameError
83
+ # next!
84
+ end
85
+ end
86
+ @@error_map = hash
87
+ end
88
+
89
+ # Creates useful exceptions from @@conn.err output
8
90
  # Returns [exception, message] based on err2string
9
91
  def LDAP.err2exception(errno=0)
10
- err = LDAP::err2string(errno)
11
- err = err.split(' ').collect {|w| w.capitalize }.join('')
12
- err.gsub!(/[^A-Za-z]/, '')
13
- # If the exception exists - raise it!
92
+ need_to_rebuild = true
14
93
  begin
15
- exc = LDAP.const_get(err)
94
+ exc = LDAP.const_get(@@error_map[errno])
16
95
  rescue NameError
17
- # Doesn't exist :-)
18
- LDAP.module_eval(<<-end_module_eval)
19
- class #{err} < LDAP::ResultError
20
- end
21
- end_module_eval
22
- exc = LDAP.const_get(err)
96
+ if need_to_rebuild
97
+ generate_err2exceptions()
98
+ need_to_rebuild = false
99
+ retry
100
+ end
101
+ exc = RuntimeError
23
102
  end
24
103
  return [exc, err2string(errno)]
25
104
  end
data/lib/activeldap.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby -W0
1
+ #!/usr/bin/ruby
2
2
  # = Ruby/ActiveLDAP
3
3
  #
4
4
  # "Ruby/ActiveLDAP" Copyright (C) 2004,2005 Will Drewry mailto:will@alum.bu.edu
@@ -913,7 +913,7 @@ require 'activeldap/configuration'
913
913
 
914
914
 
915
915
  module ActiveLDAP
916
- VERSION = "0.7.0"
916
+ VERSION = "0.7.1"
917
917
  end
918
918
 
919
919
  ActiveLDAP::Base.class_eval do
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: ruby-activeldap-debug
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.7.0
7
- date: 2006-05-03 00:00:00 +01:00
6
+ version: 0.7.1
7
+ date: 2006-05-04 00:00:00 +01:00
8
8
  summary: Ruby/ActiveLDAP is a object-oriented API to LDAP
9
9
  require_paths:
10
10
  - lib