libldap-ruby and \000

B

Bedo Sandor

--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--
 
B

Bedo Sandor

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.



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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top