Skip to content

Commit

Permalink
move some logic from canonical_dn into explode_dn and add some more
Browse files Browse the repository at this point in the history
tests for DNs
  • Loading branch information
gbarr committed Jan 31, 2002
1 parent 6c3cf02 commit f22b915
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 13 deletions.
25 changes: 16 additions & 9 deletions lib/Net/LDAP/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require Exporter;
canonical_dn
ldap_explode_dn
);
$VERSION = "0.07";
$VERSION = "0.08";

=item ldap_error_name ( NUM )
Expand Down Expand Up @@ -286,13 +286,7 @@ sub canonical_dn {
my @t = sort keys %$h;
join($plus,
map {
my $val = $h->{$_};
if ($val !~ /^#/) {
$val =~ s/([\\",=+<>#;])/\\$1/g;
$val =~ s/([\x00-\x1f\x7f-\xff])/sprintf("\\%02x",ord($1))/eg;
$val =~ s/(^\s+|\s+$)/"\\20" x length $1/ge;
}
"$_=$val";
"$_=$h->{$_}";
} $rev ? reverse(@t) : @t)
} $rev ? reverse(@dn) : @dn);

Expand Down Expand Up @@ -326,6 +320,16 @@ Uppercases type names.
Removes the leading OID. characters if the type is an OID instead
of a name.
=item *
Escapes all RFC 2253 special characters, and any other character
where the ASCII code is <32 or >= 127, with a backslash and a two
digit hex code.
=item *
Converts all leading and trailing spaces in values to be \20.
=back
B<Note> values that are hex encoded (ie start with a #) are not
Expand Down Expand Up @@ -365,6 +369,9 @@ sub ldap_explode_dn {
$val =~ s/\\([\\ ",=+<>#;]|[0-9a-fA-F]{2})
/length($1)==1 ? $1 : chr(hex($1))
/xeg;
$val =~ s/([\\",=+<>#;])/\\$1/g;
$val =~ s/([\x00-\x1f\x7f-\xff])/sprintf("\\%02x",ord($1))/eg;
$val =~ s/(^\s+|\s+$)/"\\20" x length $1/ge;
}

$rdn{uc $type} = $val;
Expand Down Expand Up @@ -394,7 +401,7 @@ terms as Perl itself.
=for html <hr>
I<$Id: Util.pm,v 1.13 2001/11/10 06:29:54 gbarr Exp $>
I<$Id: Util.pm,v 1.14 2002/01/31 15:25:52 gbarr Exp $>
=cut

Expand Down
103 changes: 99 additions & 4 deletions t/01canon_dn.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,104 @@ my @tests = map { /^\s*(\w\S+)\s+(.*)/ } split(/\n/,<<'EOS');
same cn=Clif Harden+IDNumber="a0125589 ",ou=tiPerson,ou=person,o=ti,c=us
ref CN=\20\20Graham Barr\20\20,OU=person,O=vc,C=us
same Cn=" Graham Barr ",OU=person,O=vc,C=us
same cn=" Graham \20Barr\20 ",OU=person,O=vc,C=us
ref CN=\20\20Graham Barr\20\20,OU=person,O=vc,C=us
same Cn=" Graham Barr ",OU=person,O=vc,C=us
same cn=" Graham \20Barr\20 ",OU=person,O=vc,C=us
# empty
ref
ref UID=jsmith,DC=example,DC=net
same UID=jsmith,DC=example,DC=net
ref CN=J. Smith+OU=Sales,DC=example,DC=net
same OU=Sales+CN=J. Smith,DC=example,DC=net
ref CN=John Smith\, III,DC=example,DC=net
same CN=John Smith\, III,DC=example,DC=net
same CN=John Smith\2C III,DC=example,DC=net
ref CN=Before\\0dAfter,DC=example,DC=net
same CN=Before\\0dAfter,DC=example,DC=net
ref CN=\#John Smith\20,DC=example,DC=net
same CN=\23John Smith\20,DC=example,DC=net
same CN=\#John Smith\ ,DC=example,DC=net
ref 1.3.6.1.4.1.1466.0=#04024869,DC=example,DC=com
same 1.3.6.1.4.1.1466.0=#04024869,DC=example,DC=com
ref CN=Lu\\C4\\8Di\\C4\\87
same CN=Lu\\C4\\8Di\\C4\\87
# empty value
ref 1.1.1=
# option
bad uid;x-option=jsmith
# invalid attribute type name
bad at_tr=jsmith
# invalid attribute type name
bad -attr=jsmith
# invalid attribute type name
#bad OID.1.1=jsmith
# invalid numeric OID
bad 1..1=jsmith
# invalid numeric OID
bad 1.1.=jsmith
# invalid numeric OID
#bad 01.1=jsmith
# invalid numeric OID
bad 1.ff=jsmith
# invalid HEX form
bad 1.1.1=#GG
# invalid HEX form
bad 1.1.1=#000
# invalid HEX form
bad 1.1.1=#F
# invalid HEX form
bad 1.1.1=#
# spaces
#bad UID=jsmith, DC=example, DC=net
# extra comma
bad UID=jsmith,,DC=example,DC=net
# semi-colons
#bad UID=jsmith;DC=example;DC=net
# quotes
#bad CN="John Smith",DC=example,DC=net
# brackets
bad <UID=jsmith,DC=example,DC=net>
# unescaped ,
bad UID=john,smith
# unescaped +
bad UID=john+smith
# invalid escape of ? or unescaped \
bad UID=john\?smith
# invalid hex escape
bad UID=john\Fsmith
# invalid hex escape
bad UID=john\GGsmith
EOS
Expand All @@ -68,7 +163,7 @@ while(my($op,$dn) = splice(@tests,0,2)) {
}
elsif ($op eq 'bad') {
if ($failed = defined $canon) {
print "'$dn' should not have parsed\n";
print "'$dn' should not have parsed\n '$canon'\n";
}
}
elsif ( $op eq 'same' ) {
Expand Down

0 comments on commit f22b915

Please sign in to comment.