From: Bedo Sandor Date: 2004-01-05T19:15:13+09:00 Subject: libldap-ruby and \000 --opJtzjQTFsWo+cga Content-Type: text/plain; charset=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; charset=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--