| 1 | # Copyright (c) 1998 Graham Barr <gbarr@pobox.com>. All rights reserved. | ||||||||||||||||||||||||||||
| 2 | # This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||
| 3 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package URI::_ldap; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '5.40'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use URI::Escape qw(uri_unescape); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 39 | ▶ | sub _ldap_elem { | ||||||||||||||||||||||||||
|
Subroutine
_ldap_elem: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 15 | 39 | my $self = shift; | |||||||||||||||||||||||||||
| 16 | 39 | my $elem = shift; | |||||||||||||||||||||||||||
| 17 | 39 | my $query = $self->query; | |||||||||||||||||||||||||||
| 18 | 39 | ▶ | my @bits = (split(/\?/, defined($query) ? $query : ""), ("") x 4); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 39 | my $old = $bits[$elem]; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 39 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 17 | my $new = shift; | |||||||||||||||||||||||||||
| 23 | 17 | $new =~ s/\?/%3F/g; | |||||||||||||||||||||||||||
| 24 | 17 | $bits[$elem] = $new; | |||||||||||||||||||||||||||
| 25 | 17 | $query = join("?", @bits); | |||||||||||||||||||||||||||
| 26 | 17 | $query =~ s/\?+$//; | |||||||||||||||||||||||||||
| 27 | 17 | ▶ | $query = undef unless length($query); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 17 | $self->query($query); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 39 | $old; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 8 | ▶ | sub dn { | ||||||||||||||||||||||||||
|
Subroutine
dn: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 8 | my $old = shift->path(@_); | |||||||||||||||||||||||||||
| 36 | 8 | $old =~ s:^/::; | |||||||||||||||||||||||||||
| 37 | 8 | uri_unescape($old); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 11 | ▶ | sub attributes { | ||||||||||||||||||||||||||
|
Subroutine
attributes: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 11 | my $self = shift; | |||||||||||||||||||||||||||
| 42 | my $old = _ldap_elem($self, 0, | ||||||||||||||||||||||||||||
| 43 | 11 | ▶ | @_ ? join(",", map { my $tmp = $_; $tmp =~ s/,/%2C/g; $tmp } @_) : ()); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 11 | ▶ | return $old unless wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 5 | map { uri_unescape($_) } split(/,/, $old); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 10 | ▶ | sub _scope { | ||||||||||||||||||||||||||
|
Subroutine
_scope: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 49 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 50 | 10 | my $old = _ldap_elem($self, 1, @_); | |||||||||||||||||||||||||||
| 51 | 10 | ▶ | return undef unless defined wantarray && defined $old; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined wantarray and defined $old
MC/DC0%0/2
defined wantarray and defined $old
defined wantarray
defined $old
Truth table33%1/3
A and B
A= defined wantarrayB= defined $old
| |||||||||||||||||||||||||||||
| 52 | 10 | uri_unescape($old); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 9 | ▶ | sub scope { | ||||||||||||||||||||||||||
|
Subroutine
scope: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | 9 | my $old = &_scope; | |||||||||||||||||||||||||||
| 57 | 9 | ▶ | $old = "base" unless length $old; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 9 | $old; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 11 | ▶ | sub _filter { | ||||||||||||||||||||||||||
|
Subroutine
_filter: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 62 | 11 | my $self = shift; | |||||||||||||||||||||||||||
| 63 | 11 | my $old = _ldap_elem($self, 2, @_); | |||||||||||||||||||||||||||
| 64 | 11 | ▶ | return undef unless defined wantarray && defined $old; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined wantarray and defined $old
MC/DC0%0/2
defined wantarray and defined $old
defined wantarray
defined $old
Truth table33%1/3
A and B
A= defined wantarrayB= defined $old
| |||||||||||||||||||||||||||||
| 65 | 11 | uri_unescape($old); # || "(objectClass=*)"; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 10 | ▶ | sub filter { | ||||||||||||||||||||||||||
|
Subroutine
filter: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | 10 | my $old = &_filter; | |||||||||||||||||||||||||||
| 70 | 10 | ▶ | $old = "(objectClass=*)" unless length $old; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 10 | $old; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 7 | ▶ | sub extensions { | ||||||||||||||||||||||||||
|
Subroutine
extensions: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 76 | 7 | my @ext; | |||||||||||||||||||||||||||
| 77 | 7 | ▶ | while (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 5 | my $key = shift; | |||||||||||||||||||||||||||
| 79 | 5 | my $value = shift; | |||||||||||||||||||||||||||
| 80 | push( | ||||||||||||||||||||||||||||
| 81 | @ext, | ||||||||||||||||||||||||||||
| 82 | join("=", | ||||||||||||||||||||||||||||
| 83 | 5 | ▶ | map { $_ = "" unless defined; s/,/%2C/g; $_ } $key, $value) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 7 | ▶ | @ext = join(",", @ext) if @ext; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 7 | my $old = _ldap_elem($self, 3, @ext); | |||||||||||||||||||||||||||
| 88 | 7 | ▶ | return $old unless wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 4 | map { uri_unescape($_) } map {/^([^=]+)=(.*)$/} split(/,/, $old); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 2 | ▶ | sub canonical { | ||||||||||||||||||||||||||
|
Subroutine
canonical: called CC=9 SCAR=22.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 93 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 94 | 2 | my $other = $self->_nonldap_canonical; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | # The stuff below is not as efficient as one might hope... | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 2 | ▶ | $other = $other->clone if $other == $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | $other->dn(_normalize_dn($other->dn)); | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # Should really know about mixed case "postalAddress", etc... | ||||||||||||||||||||||||||||
| 103 | 2 | $other->attributes(map lc, $other->attributes); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # Lowercase scope, remove default | ||||||||||||||||||||||||||||
| 106 | 2 | my $old_scope = $other->scope; | |||||||||||||||||||||||||||
| 107 | 2 | my $new_scope = lc($old_scope); | |||||||||||||||||||||||||||
| 108 | 2 | ▶ | $new_scope = "" if $new_scope eq "base"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 2 | ▶ | $other->scope($new_scope) if $new_scope ne $old_scope; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # Remove filter if default | ||||||||||||||||||||||||||||
| 112 | 2 | my $old_filter = $other->filter; | |||||||||||||||||||||||||||
| 113 | 2 | ▶ | $other->filter("") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
lc $old_filter eq "(objectclass=*)" or lc $old_filter eq "objectclass=*"
MC/DC0%0/2
lc $old_filter eq "(objectclass=*)" or lc $old_filter eq "objectclass=*"
lc $old_filter eq "(objectclass=*)"
lc $old_filter eq "objectclass=*"
Truth table33%1/3
A or B
A= lc $old_filter eq "(objectclass=*)"B= lc $old_filter eq "objectclass=*"
| |||||||||||||||||||||||||||||
| 114 | if lc($old_filter) eq "(objectclass=*)" | ||||||||||||||||||||||||||||
| 115 | || lc($old_filter) eq "objectclass=*"; | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | # Lowercase extensions types and deal with known extension values | ||||||||||||||||||||||||||||
| 118 | 2 | my @ext = $other->extensions; | |||||||||||||||||||||||||||
| 119 | 2 | ▶ | for (my $i = 0; $i < @ext; $i += 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 4 | my $etype = $ext[$i] = lc($ext[$i]); | |||||||||||||||||||||||||||
| 121 | 4 | ▶ | if ($etype =~ /^!?bindname$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 2 | $ext[$i + 1] = _normalize_dn($ext[$i + 1]); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | 2 | ▶ | $other->extensions(@ext) if @ext; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 2 | $other; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | sub _normalize_dn # RFC 2253 | ||||||||||||||||||||||||||||
| 131 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_normalize_dn: called CC=2 SCAR=12.4
| |||||||||||||||||||||||||||||
| 132 | 4 | my $dn = shift; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 4 | return $dn; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | # The code below will fail if the "+" or "," is embedding in a quoted | ||||||||||||||||||||||||||||
| 137 | # string or simply escaped... | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | my @dn = split(/([+,])/, $dn); | |||||||||||||||||||||||||||
| 140 | 0 | for (@dn) { | |||||||||||||||||||||||||||
| 141 | 0 | s/^([a-zA-Z]+=)/lc($1)/e; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 0 | join("", @dn); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 1 | 1; | |||||||||||||||||||||||||||