This file is indexed.

/usr/share/perl5/Net/LDAP/FilterBuilder.pm is in libnet-ldap-filterbuilder-perl 1.0004-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#
# $HeadURL: https://svn.oucs.ox.ac.uk/people/oliver/pub/cpan/libnet-ldap-filterbuilder-perl/trunk/lib/Net/LDAP/FilterBuilder.pm $
# $LastChangedRevision: 767 $
# $LastChangedDate: 2010-06-11 15:37:15 +0100 (Fri, 11 Jun 2010) $
# $LastChangedBy: oliver $
#
package Net::LDAP::FilterBuilder;

use strict;
use warnings FATAL => 'all';

our $VERSION = '1.0004';
$VERSION = eval $VERSION; # numify for warning-free dev releases

use overload '""' => \&as_str;

sub escape {
    my $class = shift;
    my $value = shift;
    for ( $value ) {
        s{\\}{\\}g;
        s{\*}{\\*}g;
        s{\(}{\\(}g;
        s{\)}{\\)}g;
        s{\0}{\\0}g;
    }
    return $value;
}

sub new {
    my $proto = shift;
    my $class = ref( $proto ) || $proto;

    my $filter;

    if ( @_ == 0 ) {
        $filter = '(objectclass=*)';
    }
    elsif ( @_ == 1 ) {
        $filter = shift;
    }
    else {
        my $op = @_ % 2 ? shift : '=';
        my @parts;
        while ( my ( $attr, $val ) = splice( @_, 0, 2 ) ) {
            if ( ref( $val ) eq 'ARRAY' ) {
                push @parts, sprintf( '(|%s)', join( q{}, map $class->new( $op, $attr, $_ ), @{ $val } ) );
            }
            elsif ( ref( $val ) eq 'SCALAR' ) {
                push @parts, sprintf( '(%s%s%s)', $attr, $op, ${ $val } );
            }
            else {
                push @parts, sprintf( '(%s%s%s)', $attr, $op, $class->escape( $val ) );
            }
        }
        if ( @parts > 1 ) {
            $filter = sprintf( '(&%s)', join( q{}, @parts ) );
        }
        else {
            $filter = shift @parts;
        }
    }

    bless( \$filter, $class );
}

sub or {
    my $self = shift;

    ${ $self } = sprintf( '(|%s%s)', $self, $self->new( @_ ) );

    return $self;
}

sub and {
    my $self = shift;

    ${ $self } = sprintf( '(&%s%s)', $self, $self->new( @_ ) );

    return $self;
}

sub not {
    my $self = shift;

    ${ $self } = sprintf( '(!%s)', $self );

    return $self;
}

sub as_str {
    ${ $_[0] };
}

1;

__END__

=head1 NAME

Net::LDAP::FilterBuilder - Build LDAP filter statements

=head1 VERSION

This document refers to version 1.0004 of Net::LDAP::FilterBuilder

=head1 PURPOSE

Use this module to construct LDAP filter statments which are compliant with
the RFC 4515 syntax and also safely escape special characters. Filter
statements can be built incrementally using simple logic operations.

=head1 SYNOPSIS

 use Net::LDAP::FilterBuilder;

 my $filter1 = Net::LDAP::FilterBuilder->new( sn => 'Jones' );
 # now $filter1 eq '(sn=Jones)'

Basic logic operations such as C<and>, C<or> and C<not>:

 $filter1->and( givenName => 'David' );
 # (&(sn=Jones)(givenName=David))
 
 my $filter2 = Net::LDAP::FilterBuilder->new( sn => [ 'Jones', 'Edwards', 'Lewis' ] );
 # (|(sn=Jones)(sn=Edwards)(sn=Lewis))
 
 my $filter3 = Net::LDAP::FilterBuilder->new( givenName => 'David' )->not;
 # (!(givenName=David))

Build up filters incrementally from other FilterBuidler objects:

 my $filter4 = Net::LDAP::FilterBuilder->new( sn => ['Jones', 'Edwards'] )->and( $filter3 );
 # (&(|(sn=Jones)(sn=Edwards))(!(givenName=David)))

Special characters to LDAP will be escaped:

 my $filter5 = Net::LDAP::FilterBuilder->new( sn => 'foo*bar' );
 # (sn=foo\*bar)

To disable escaping, pass a Scalar reference:

 my $filter6 = Net::LDAP::FilterBuilder->new( sn => \'foo*bar' );
 # (sn=foo*bar)

Alternate operators are available through the three-argument constructor form:

 my $filter7 = Net::LDAP::FilterBuilder->new( '>=', dateOfBirth => '19700101000000Z' );
 # (dateOfBirth>=19700101000000Z)

=head1 DESCRIPTION

This is a convenience module which greatly simplifies the construction of LDAP
query filter statments, which are described in RFC 4515 and also the
L<Net::LDAP::Filter> manual page. 

=head1 USAGE

To make any filter, call the constructor C<new> with the attribute and value
to match:

 my $filter = Net::LDAP::FilterBuilder->new( sn => 'Jones' );

The value returned is an object, but stringifies to the current query:

 print "success" if $filter eq '(sn=Jones)';
 # prints "success"

However you can refine the filter statement using three additional methods for
the logical operations C<and>, C<or> and C<not>, as shown in the L<"SYOPSIS">
section, above, and the L<"METHODS"> section below.

There are two ways to refine a filter. Either call the logic method with a new
attribute and value, or call a logic method and pass another
Net::LDAP::FilterBuilder object. These two practices are also shown in the
L<"SYNOPSIS"> section, above.

=head2 Comparison Operators

By default the module uses an equal operator between the attribute and value.
To select an alternate operator, use the three agurment form of the
constructor:

 my $filter = Net::LDAP::FilterBuilder->new( '>=', dateOfBirth => '19700101000000Z' );
 # (dateOfBirth>=19700101000000Z)

Note that this module is not aware of the list of valid operators, it simply
takes the first argument to be the operator, whatever it might be.

=head2 Special Character Escaping

If you happen to include one of the small set of characters which are of
special significance to LDAP filter statments in your value argument, then
those characters will be escaped. The list of characters is:

 ( ) * \ NUL 

To avoid this pass in a scalar reference as the value argument. For example to
enable a wildcard (substring) match on a value:

 my $filter = Net::LDAP::FilterBuilder->new( sn => \'foo*bar' );
 # (sn=foo*bar)

=head1 METHODS

=over 4

=item B<as_str>

Returns the string representation of the LDAP filter.  Note that the
object will stringify to this value in string context, too.

=item B<and>(FILTERSPEC)

Logically conjoins this filter with the one specified by FILTERSPEC.
FILTERSPEC may be a L<Net::LDAP::FilterBuilder> object, or a
hash representation of the filter as taken by L<B<new>>.

Returns the newly-conjoined L<Net::LDAP::FilterBuilder>.

=item B<or>(FILTERSPEC)

Logically disjoins this filter with the one specified by FILTERSPEC.
FILTERSPEC may be a L<Net::LDAP::FilterBuilder> object, or a
hash representation of the filter as taken by L<B<new>>.

Returns the newly-disjoined L<Net::LDAP::FilterBuilder>.

=item B<not>

Logically complements this filter.

Returns the newly-negated L<Net::LDAP::FilterBuilder>.

=back

=head1 AUTHOR

Originally written by Ray Miller.

=head1 MAINTAINER

Oliver Gorwits C<< <oliver.gorwits@oucs.ox.ac.uk> >>

=head1 COPYRIGHT & LICENSE

Copyright (c) The University of Oxford 2008.

This library is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.

=cut