This file is indexed.

/usr/share/perl5/LWP/Protocol/ldap.pm is in libnet-ldap-perl 1:0.4300-2ubuntu1.

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
# Copyright (c) 1998-2004 Graham Barr <gbarr@pobox.com>. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.

package LWP::Protocol::ldap;

use Carp ();

use HTTP::Status ();
use HTTP::Negotiate ();
use HTTP::Response ();
use LWP::MediaTypes ();
require LWP::Protocol;
@ISA = qw(LWP::Protocol);

$VERSION = "1.11";

use strict;
eval {
  require Net::LDAP;
};
my $init_failed = $@ ? $@ : undef;

sub request {
  my($self, $request, $proxy, $arg, $size, $timeout) = @_;

  $size = 4096 unless $size;

  LWP::Debug::trace('()') if defined &LWP::Debug::trace;

  # check proxy
  if (defined $proxy)
  {
    return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
                 'You can not proxy through the ldap';
  }

  my $url = $request->url;
  if ($url->scheme ne 'ldap') {
    my $scheme = $url->scheme;
    return new HTTP::Response &HTTP::Status::RC_INTERNAL_SERVER_ERROR,
            "LWP::Protocol::ldap::request called for '$scheme'";
  }

  # check method
  my $method = $request->method;

  unless ($method eq 'GET') {
    return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
                 'Library does not allow method ' .
                 "$method for 'ldap:' URLs";
  }

  if ($init_failed) {
    return new HTTP::Response &HTTP::Status::RC_INTERNAL_SERVER_ERROR,
            $init_failed;
  }

  my $host     = $url->host;
  my $port     = $url->port;
  my $userinfo = $url->userinfo;
  my ($user, $password) = defined($userinfo) ? split(":", $userinfo, 2) : ();

  # Create an initial response object
  my $response = new HTTP::Response &HTTP::Status::RC_OK, "Document follows";
  $response->request($request);

  my $ldap = new Net::LDAP($host, port => $port);

  if ($user) {
    my $mesg = $ldap->bind($user, password => $password);

    if ($mesg->code) {
      my $res = new HTTP::Response &HTTP::Status::RC_BAD_REQUEST, "LDAP return code " . $mesg->code;
      $res->content_type("text/plain");
      $res->content($mesg->error);
      return $res;
    }
  }

  my $dn = $url->dn;
  my @attrs = $url->attributes;
  my $scope = $url->scope || "base";
  my $filter = $url->filter;
  my @opts = (scope => $scope);
  my %extn = $url->extensions;
  my $format = lc($extn{'x-format'} || 'html');

  if (my $accept = $request->header('Accept')) {
    $format = 'ldif' if $accept =~ m!\btext/ldif\b!;
  }
  
  push @opts, "base" => $dn if $dn;
  push @opts, "filter" => $filter if $filter;
  push @opts, "attrs" => \@attrs if @attrs;

  my $mesg = $ldap->search(@opts);
  if ($mesg->code) {
    my $res = new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
         "LDAP return code " . $ldap->code;
    $res->content_type("text/plain");
    $res->content($ldap->error);
    return $res;
  }
  elsif ($format eq 'ldif') {
    require Net::LDAP::LDIF;
    open(my $fh, ">", \my $content);
    my $ldif = Net::LDAP::LDIF->new($fh,"w", version => 1);
    while(my $entry = $mesg->shift_entry) {
      $ldif->write_entry($entry);
    }
    $ldif->done;
    close($fh);
    $response->header('Content-Type' => 'text/ldif');
    $response->header('Content-Length', length($content));
    $response = $self->collect_once($arg, $response, $content)
	if ($method ne 'HEAD');
  }
  else {
    my $content = "<head><title>Directory Search Results</title></head>\n<body>";
    my $entry;
    my $index;

    for($index = 0 ; $entry = $mesg->entry($index) ; $index++ ) {
      my $attr;

      $content .= $index ? qq{<tr><th colspan="2"><hr>&nbsp</tr>\n} : "<table>";

      $content .= qq{<tr><th colspan="2">} . $entry->dn . "</th></tr>\n";

      foreach $attr ($entry->attributes) {
        my $vals = $entry->get_value($attr, asref => 1);
        my $val;

        $content .= q{<tr><td align="right" valign="top"};
        $content .= q{ rowspan="} . scalar(@$vals) . q{"}
          if (@$vals > 1);
        $content .= ">" . $attr  . "&nbsp</td>\n";

        my $j = 0;
        foreach $val (@$vals) {
	  $val = qq!<a href="$val">$val</a>! if $val =~ /^https?:/;
	  $val = qq!<a href="mailto:$val">$val</a>! if $val =~ /^[-\w]+\@[-.\w]+$/;
          $content .= "<tr>" if $j++;
          $content .= "<td>" . $val . "</td></tr>\n";
        }
      }
    }

    $content .= "</table>" if $index;
    $content .= "<hr>";
    $content .= $index ? sprintf("%s Match%s found",$index, $index>1 ? "es" : "")
		       : "<b>No Matches found</b>";
    $content .= "</body>\n";
    $response->header('Content-Type' => 'text/html');
    $response->header('Content-Length', length($content));
    $response = $self->collect_once($arg, $response, $content)
	if ($method ne 'HEAD');

  }

  $ldap->unbind;

  $response;
}

1;