ruby-activeldap 0.4.3 → 0.4.4

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 (3) hide show
  1. data/lib/activeldap/base.rb +26 -12
  2. data/lib/activeldap.rb +21 -9
  3. metadata +2 -2
@@ -249,7 +249,10 @@ module ActiveLDAP
249
249
  # This method deletes the LDAP connection object.
250
250
  # This does NOT reset any overridden values from a Base.connect call.
251
251
  def Base.close
252
+ @@conn.unbind unless @@conn.nil?
252
253
  @@conn = nil
254
+ # Make sure it is cleaned up
255
+ ObjectSpace.garbage_collect
253
256
  end
254
257
 
255
258
  # Return the LDAP connection object currently in use
@@ -466,7 +469,6 @@ module ActiveLDAP
466
469
  # If multiple values exist for dnattr, the first one put here will be authoritative
467
470
  # TODO: Add support for relative distinguished names
468
471
  def initialize(val='')
469
- @@logger.debug("stub: initialize(#{val.inspect}) called")
470
472
  if val.class != String
471
473
  raise TypeError, "Object key must be a String"
472
474
  end
@@ -511,13 +513,20 @@ module ActiveLDAP
511
513
  # Save DN
512
514
  @dn = m.dn
513
515
  # Load up data into tmp
514
- @@logger.debug("loading entry: #{@dn}")
516
+ @@logger.debug("loading entry: #{@dn}")
515
517
  m.attrs.each do |attr|
516
518
  # Load with subtypes just like @data
517
- @@logger.debug("calling make_subtypes for m.vals(attr).dup")
519
+ @@logger.debug("calling make_subtypes for m.vals(attr).dup")
518
520
  safe_attr, value = make_subtypes(attr, m.vals(attr).dup)
519
- @@logger.debug("finished make_subtypes for #{attr}")
520
- @ldap_data[safe_attr] = value
521
+ @@logger.debug("finished make_subtypes for #{attr}")
522
+ # Add subtype to any existing values
523
+ if @ldap_data.has_key? safe_attr
524
+ value.each do |v|
525
+ @ldap_data[safe_attr].push(v)
526
+ end
527
+ else
528
+ @ldap_data[safe_attr] = value
529
+ end
521
530
  end
522
531
  end
523
532
  @exists = true
@@ -754,7 +763,7 @@ module ActiveLDAP
754
763
  value = data[name+suffix]
755
764
 
756
765
  # Detect subtypes and account for them
757
- binary = LDAP::LDAP_MOD_BVALUES if suffix.match(/;binary(;|$)/)
766
+ binary = LDAP::LDAP_MOD_BVALUES if Base.schema.binary? name
758
767
 
759
768
  replaceable.push(name+suffix)
760
769
  if pair[1] != value
@@ -786,9 +795,11 @@ module ActiveLDAP
786
795
 
787
796
  if not replaceable.member? name+suffix
788
797
  # Detect subtypes and account for them
789
- binary = LDAP::LDAP_MOD_BVALUES if suffix.match(/;binary(;|$)/)
798
+ binary = LDAP::LDAP_MOD_BVALUES if Base.schema.binary? name
790
799
  @@logger.debug("adding attribute to existing entry: #{name+suffix}: #{value.inspect}")
791
- entry.push(LDAP.mod(LDAP::LDAP_MOD_ADD|binary, name + suffix, value)) unless value.empty?
800
+ # REPLACE will function like ADD, but doesn't hit EQUALITY problems
801
+ # TODO: Added equality(attr) to Schema2
802
+ entry.push(LDAP.mod(LDAP::LDAP_MOD_REPLACE|binary, name + suffix, value)) unless value.empty?
792
803
  end
793
804
  end
794
805
  @@logger.debug("#write: traversing data complete")
@@ -810,7 +821,7 @@ module ActiveLDAP
810
821
  data.each do |pair|
811
822
  if pair[1].size > 0 and pair[0] != 'objectClass' and pair[0] != @attr_methods[dnattr()]
812
823
  # Detect subtypes and account for them
813
- if pair[0].match(/;binary(;|$)/)
824
+ if Base.schema.binary? pair[0].split(/;/)[0]
814
825
  binary = LDAP::LDAP_MOD_BVALUES
815
826
  else
816
827
  binary = 0
@@ -825,7 +836,7 @@ module ActiveLDAP
825
836
  @@logger.debug("#write: add successful")
826
837
  @exists = true
827
838
  rescue LDAP::ResultError => detail
828
- raise WriteError, "Could not add LDAP entry: #{detail}"
839
+ raise WriteError, "Could not add LDAP entry[#{Base.conn.err2string(Base.conn.err)}]: #{detail}"
829
840
  end
830
841
  end
831
842
  @@logger.debug("#write: resetting @ldap_data to a dup of @data")
@@ -872,7 +883,7 @@ module ActiveLDAP
872
883
  if attr.nil?
873
884
  raise RuntimeError, 'attr argument must not be nil.'
874
885
  end
875
- binary = Base.schema.binary? attr
886
+ binary = Base.schema.binary_required? attr
876
887
  single = Base.schema.single_value? attr
877
888
  case value.class.to_s
878
889
  when 'Array'
@@ -880,7 +891,10 @@ module ActiveLDAP
880
891
  raise TypeError, "This attribute can only have a single value"
881
892
  end
882
893
  value.map! do |entry|
883
- entry = entry.to_s unless entry.class == Hash
894
+ if entry.class != Hash
895
+ @@logger.debug("coercing value for #{attr} into a string because nested values exceeds a useful depth: #{entry.inspect} -> #{entry.to_s}")
896
+ entry = entry.to_s
897
+ end
884
898
  entry = attribute_input_handler(attr, entry)[0]
885
899
  end
886
900
  when 'Hash'
data/lib/activeldap.rb CHANGED
@@ -2,7 +2,6 @@
2
2
  # = Ruby/ActiveLDAP
3
3
  #
4
4
  # "Ruby/ActiveLDAP" Copyright (C) 2004 Will Drewry mailto:will@alum.bu.edu
5
- # Documentation Version 0.3
6
5
  #
7
6
  # == Introduction
8
7
  #
@@ -214,6 +213,11 @@
214
213
  # that field out to default to ['top'] only. Then you can let each application
215
214
  # choose what objectClasses their objects should have by calling the method e.g.
216
215
  # Group#objectClass=(value).
216
+ #
217
+ # Note that is can be very important to define the default :classes value. Due to
218
+ # implementation choices with most LDAP servers, once an object is created, its
219
+ # structural objectclasses may not be removed (or replaced). Setting a sane default
220
+ # may help avoid programmer error later.
217
221
  #
218
222
  # :classes isn't the only optional argument. If :dnattr is left off, it defaults
219
223
  # to 'cn'. If :prefix is left off, it will default to 'ou=CLASSNAME'. In this
@@ -679,21 +683,29 @@
679
683
  # Anytime a LDAP subtype is required, you must encapsulate the data in a Hash.
680
684
  #
681
685
  # But wait a minute, I just read in a binary certificate without wrapping it up.
682
- # So any binary attribute will automagically get wrapped in {'binary' => value}
683
- # if you don't do it. This keeps your #writes from breaking, and my code from
684
- # crying. For correctness, I could have easily done the following:
686
+ # So any binary attribute _that requires ;binary subtyping_ will automagically
687
+ # get wrapped in {'binary' => value} if you don't do it. This keeps your #writes
688
+ # from breaking, and my code from crying. For correctness, I could have easily
689
+ # done the following:
685
690
  #
686
691
  # irb> user.userCertificate = {'binary' => File.read('example.der')}
687
692
  #
688
- # Really, it's up to you. The only subtypes defined in LDAPv3 are lang-* and
689
- # binary. These can be nested through:
693
+ # You should note that some binary data does not use the binary subtype all the time.
694
+ # One example is jpegPhoto. You can use it as jpegPhoto;binary or just as jpegPhoto.
695
+ # Since the schema dictates that it is a binary value, Ruby/ActiveLDAP will write
696
+ # it as binary, but the subtype will not be automatically appended as above. The
697
+ # use of the subtype on attributes like jpegPhoto is ultimately decided by the
698
+ # LDAP site policy and not by any programmatic means.
699
+ #
700
+ # The only subtypes defined in LDAPv3 are lang-* and binary. These can be nested
701
+ # though:
690
702
  #
691
703
  # irb> user.cn = [{'lang-JP-jp' => {'binary' => 'somejp'}}]
692
704
  #
693
705
  # As I understand it, OpenLDAP does not support nested subtypes, but some
694
706
  # documentation I've read suggests that Netscape's LDAP server does. I only
695
- # have access to OpenLDAP. If anyone tests thisout, please let me know how it
696
- # goes!.
707
+ # have access to OpenLDAP. If anyone tests this out, please let me know how it
708
+ # goes!
697
709
  #
698
710
  #
699
711
  # And that pretty much wraps up this section.
@@ -880,7 +892,7 @@ require 'activeldap/configuration'
880
892
  require 'activeldap/schema2'
881
893
 
882
894
  module ActiveLDAP
883
- VERSION = "0.4.3"
895
+ VERSION = "0.4.4"
884
896
  end
885
897
 
886
898
  ActiveLDAP::Base.class_eval do
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.1
3
3
  specification_version: 1
4
4
  name: ruby-activeldap
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.3
7
- date: 2004-10-08
6
+ version: 0.4.4
7
+ date: 2004-10-10
8
8
  summary: Ruby/ActiveLDAP is a object-oriented API to LDAP
9
9
  require_paths:
10
10
  - lib