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.
libldapbug.rb (1.38 KB)
···
–
bSanyI
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 ttate@ttsky.net
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:
···
On Mon, Jan 05, 2004 at 11:15:09AM +0100, Bedo Sandor wrote:
#!/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
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
···
On Mon, Jan 05, 2004 at 11:00:46PM +0900, Takaaki Tateishi wrote:
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 ])
]
–
bSanyI