"Klunder, JAA (Hans)" <J.A...@rf...> wrote:
> Hello,
>
> Is there a simple way to split a DN into RDN's. Just splitting on comma's
> is risky since the value of the RDN can contain a comma itself.
>
> I'm looking for something similar to explode_dn in mozilla ldap.
>
> Mozilla also has a $entry->hasValue method which can be quite convenient,
> is there an equivalent in Net::LDAP ?
>
> Thanks in advance,
>
> Hans Klunder
There isn't. (Net::LDAP doesn't provide much in the way of help
manipulating values from the directory. This is a case where syntax
handlers would be nice. If I could ever get around to finishing them!)
Anyway, something like this regex *nearly* works:
while ($dn =~ m{
\s*
(\d[0-9\.]+|[a-zA-Z][a-zA-Z0-9-]+) # type
=
(\#[a-fA-F0-9]+| # hex value
"[^"\\]*(?:\\.[^"\\]*)*"| # v2 quoted value
[^\\,;+]*(?:\\[a-zA-Z0-9][a-zA-Z0-9][^\\,;+]*)*) # normal value
([,;+]?) # separator
}gx) {
print "type $1\n";
print "value $2\n";
print "separator $3\n";
}
For some reason, this always stops matching before the penultimate RDN, eg
"cn=Chris Ridd,ou=Engineering,o=MessagingDirect,c=CA" prints out the cn and
ou.
Can any regex wizards spot the problem?
Would the equivalent of the $entry->hasValue thing be Net::LDAP's get
method returning undef? I can't remember if this is what Net::LDAP does,
and I don't know what the Mozzilla library does.
Cheers,
Chris
|