Professional Web Applications Themes

libldap-ruby and

--opJtzjQTFsWo+cga Content-Type: text/plain; cht=us-ascii Content-Disposition: inline Hi, please let's have a look at my little ruby program! It adds an entry to an ldap server and the binary fields are ended at the first

Thread: libldap-ruby and \000

0 char. Is it the libldap-ruby library's error? Or maybe the underlaying OpenLDAP library does something? (Strings in C are terminated exactly this way. Is there any connection?) Or am I doing something wrong? How can I add binary data containing the

Thread: libldap-ruby and \000

character? The programs output is this: | |written: "after the

Thread: libldap-ruby and \000

0 character THIS IS ALWAYS LOST Why!??" |read: "after the " | The ...

  1. #1

    Default libldap-ruby and \000

    --opJtzjQTFsWo+cga
    Content-Type: text/plain; cht=us-ascii
    Content-Disposition: inline


    Hi,
    please let's have a look at my little ruby program! It adds
    an entry to an ldap server and the binary fields are ended at
    the first \000 char. Is it the libldap-ruby library's error?
    Or maybe the underlaying OpenLDAP library does something?
    (Strings in C are terminated exactly this way. Is there
    any connection?) Or am I doing something wrong?

    How can I add binary data containing the \0 character?

    The programs output is this:

    |
    |written: "after the \000 character THIS IS ALWAYS LOST Why!??"
    |read: "after the "
    |

    The first string is added, the second has read back after the
    add method.

    --
    bSanyI

    --opJtzjQTFsWo+cga
    Content-Type: text/plain; cht=us-ascii
    Content-Disposition: attachment; filename="libldapbug.rb"

    #!/usr/bin/ruby -w
    require 'ldap'

    $HOST = 'localhost'
    $PORT = 389
    $PROTO = 3 ## LDAPv3
    $SUFFIX = "dc=mydomain, dc=com"
    $USER = "cn=manager, #{$SUFFIX}"
    $CRED = 'secret'

    binaryData = "after the \000 character THIS IS ALWAYS LOST Why!??"

    dn = "cn=test, #{$SUFFIX}"
    entry = {
    'objectClass' => [ 'top', 'strongAuthenticationUser', 'person' ],
    'cn' => [ "test" ],
    'sn' => [ "test" ],
    'userCertificate;binary' => [ binaryData ],
    }

    ## bind
    ldap = LDAP::Conn.new($HOST, $PORT)
    ldap.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, $PROTO)
    begin
    ldap.bind($USER, $CRED)
    rescue LDAP::ResultError => msg
    $stderr.puts "\t ERROR: BIND: \"#{msg.to_s}\""
    exit 1
    end

    ## add
    begin
    entry.delete('dn')
    ldap.add(dn, entry)
    rescue LDAP::ResultError => msg
    $stderr.puts "\t ERROR: ADDING [#{dn}]: \"#{msg.to_s}\""
    $stderr.puts "DN: #{dn}"
    entry.each_key { |attr|
    entry[attr].each { |value|
    $stderr.puts "#{attr}: #{value}"
    }
    }
    exit 2
    ensure
    ldap.unbind
    end

    ## verify
    print "written: "
    p binaryData

    ldap = LDAP::Conn.new($HOST, $PORT)
    ldap.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, $PROTO)
    begin
    ldap.bind($USER, $CRED)
    ldap.search(dn, LDAP::LDAP_SCOPE_BASE, '(objectClass=*)') { |e|
    print "read: "
    p e.vals('userCertificate;binary').first
    }
    rescue LDAP::ResultError => msg
    $stderr.puts "\t ERROR: READING [#{dn}]: \"#{msg.to_s}\""
    exit 3
    ensure
    ldap.unbind
    end

    ## end.

    --opJtzjQTFsWo+cga--

    Bedo Guest

  2. #2

    Default Re: libldap-ruby and \000

    > How can I add binary data containing the \0 character?

    Could you try the following code?

    entry = [
    LDAP.mod(LDAP::LDAP_MOD_ADD, 'objectClass', [ 'top',
    'strongAuthenticationUser', 'person' ]),
    LDAP.mod(LDAP::LDAP_MOD_ADD, 'cn', [ "test" ]),
    LDAP.mod(LDAP::LDAP_MOD_ADD, 'sn', [ "test" ]),
    LDAP.mod(LDAP::LDAP_MOD_ADD | LDAP::LDAP_MOD_BVALUES,
    'userCertificate;binary', [ binaryData ])
    ]

    Now I think that it is helpful for us to convert {'key1'=>data1,...}
    into [LDAP.mod(...|LDAP::LDAP_MOD_BVALUES, 'key1', data1),...].
    In all liklihood, I will improve the conversion method so that we can
    simply add strings containing '\000' in the notation {...}.

    Thanks,
    --
    Takaaki Tateishi <net>

    Takaaki Guest

  3. #3

    Default Re: libldap-ruby and \000

    On Mon, Jan 05, 2004 at 11:00:46PM +0900, Takaaki Tateishi wrote: 
    >
    > Could you try the following code?
    >
    > entry = [
    > LDAP.mod(LDAP::LDAP_MOD_ADD, 'objectClass', [ 'top', 'strongAuthenticationUser', 'person' ]),
    > LDAP.mod(LDAP::LDAP_MOD_ADD, 'cn', [ "test" ]),
    > LDAP.mod(LDAP::LDAP_MOD_ADD, 'sn', [ "test" ]),
    > LDAP.mod(LDAP::LDAP_MOD_ADD | LDAP::LDAP_MOD_BVALUES, 'userCertificate;binary', [ binaryData ])
    > ][/ref]

    Thank You, this works. But I think hashes are more distinct
    than modify chains... Is this conversion a wrong idea?

    class Hash
    def to_ldapmodify
    tmp = []
    self.each_key { |attr|
    next if attr == 'dn'
    values = self[attr].to_a
    mod = LDAP::LDAP_MOD_ADD
    mod |= LDAP::LDAP_MOD_BVALUES if values.find { |e| e =~ /\000/ }
    tmp << LDAP.mod(mod, attr, values)
    }
    return tmp
    end
    end

    --
    bSanyI

    Bedo Guest

  4. #4

    Default Re: libldap-ruby and \000



    Hi,

    the same probleme occures with gq-0.5.0-1 on Debian/woody.
    If I modify an entry that has got a userCertificate;binary
    attribute containing an ascii zero character, the binary
    data losts from the first \0 char to the end of the attribute.
    Of cource I do not modify the userCertificate attrib, i am
    changing another (for example the mail) attribute.



    On Mon, Jan 05, 2004 at 11:15:09AM +0100, Bedo Sandor wrote: 

    Attachment: 

    --
    bSanyI


    Bedo Guest

Similar Threads

  1. libldap-ruby with TLS connection
    By Bedo Sandor in forum Ruby
    Replies: 1
    Last Post: November 13th, 02:02 PM
  2. Replies: 0
    Last Post: November 1st, 05:21 PM
  3. Replies: 1
    Last Post: October 29th, 07:52 PM
  4. RubyConf, Ruby Central, Ruby Garden temporary outage
    By dblack@superlink.net in forum Ruby
    Replies: 1
    Last Post: September 10th, 03:46 PM
  5. [ANN] ruby-freedb, ruby-serialport, ruby-mp3info moved to Rubyforge
    By guillaume.pierronnet@ratp.fr in forum Ruby
    Replies: 0
    Last Post: August 31st, 11:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •