[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
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:
>
> 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
Attachment:
> #!/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.
--
bSanyI