/usr/share/perl5/Net/LDAP/Message.pm is in libnet-ldap-perl 1:0.5800-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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | # Copyright (c) 1997-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 Net::LDAP::Message;
use Net::LDAP::Constant qw(LDAP_SUCCESS LDAP_COMPARE_TRUE LDAP_COMPARE_FALSE);
use Net::LDAP::ASN qw(LDAPRequest);
use strict;
our $VERSION = '1.12';
my $MsgID = 0;
# We do this here so when we add threading we can lock it
sub NewMesgID {
$MsgID = 1 if ++$MsgID > 65535;
$MsgID;
}
sub new {
my $self = shift;
my $type = ref($self) || $self;
my $parent = shift->inner;
my $arg = shift;
$self = bless {
parent => $parent,
mesgid => NewMesgID(),
callback => $arg->{callback} || undef,
raw => $arg->{raw} || undef,
}, $type;
$self;
}
sub code {
my $self = shift;
$self->sync unless exists $self->{resultCode};
exists $self->{resultCode}
? $self->{resultCode}
: undef
}
sub done {
my $self = shift;
exists $self->{resultCode};
}
sub dn {
my $self = shift;
$self->sync unless exists $self->{resultCode};
exists $self->{matchedDN}
? $self->{matchedDN}
: undef
}
sub referrals {
my $self = shift;
$self->sync unless exists $self->{resultCode};
exists $self->{referral}
? @{$self->{referral}}
: ();
}
sub server_error {
my $self = shift;
$self->sync unless exists $self->{resultCode};
exists $self->{errorMessage}
? $self->{errorMessage}
: undef
}
sub error {
my $self = shift;
my $return;
unless ($return = $self->server_error) {
require Net::LDAP::Util and
$return = Net::LDAP::Util::ldap_error_desc( $self->code );
}
$return;
}
sub set_error {
my $self = shift;
($self->{resultCode}, $self->{errorMessage}) = ($_[0]+0, "$_[1]");
$self->{callback}->($self)
if (defined $self->{callback});
$self;
}
sub error_name {
require Net::LDAP::Util;
Net::LDAP::Util::ldap_error_name(shift->code);
}
sub error_text {
require Net::LDAP::Util;
Net::LDAP::Util::ldap_error_text(shift->code);
}
sub error_desc {
require Net::LDAP::Util;
Net::LDAP::Util::ldap_error_desc(shift->code);
}
sub sync {
my $self = shift;
my $ldap = $self->{parent};
my $err;
until(exists $self->{resultCode}) {
$err = $ldap->sync($self->mesg_id) or next;
$self->set_error($err, 'Protocol Error')
unless exists $self->{resultCode};
return $err;
}
LDAP_SUCCESS;
}
sub decode { # $self, $pdu, $control
my $self = shift;
my $result = shift;
my $data = (values %{$result->{protocolOp}})[0];
@{$self}{keys %$data} = values %$data;
@{$self}{qw(controls ctrl_hash)} = ($result->{controls}, undef);
# free up memory as we have a result so we will not need to re-send it
delete $self->{pdu};
if ($data = delete $result->{protocolOp}{intermediateResponse}) {
my $intermediate = Net::LDAP::Intermediate->from_asn($data);
if (defined $self->{callback}) {
$self->{callback}->($self, $intermediate);
} else {
push(@{$self->{intermediate} ||= []}, $intermediate);
}
return $self;
} else {
# tell our LDAP client to forget us as this message has now completed
# all communications with the server
$self->parent->_forgetmesg($self);
}
$self->{callback}->($self)
if (defined $self->{callback});
$self;
}
sub abandon {
my $self = shift;
return if exists $self->{resultCode}; # already complete
my $ldap = $self->{parent};
$ldap->abandon($self->{mesgid});
}
sub saslref {
my $self = shift;
$self->sync unless exists $self->{resultCode};
exists $self->{sasl}
? $self->{sasl}
: undef
}
sub encode {
my $self = shift;
$self->{pdu} = $LDAPRequest->encode(@_, messageID => $self->{mesgid})
or return;
1;
}
sub control {
my $self = shift;
if ($self->{controls}) {
require Net::LDAP::Control;
my $hash = $self->{ctrl_hash} = {};
foreach my $asn (@{delete $self->{controls}}) {
my $ctrl = Net::LDAP::Control->from_asn($asn);
$ctrl->{raw} = $self->{parent}->{raw}
if ($self->{parent});
push @{$hash->{$ctrl->type} ||= []}, $ctrl;
}
}
my $ctrl_hash = $self->{ctrl_hash}
or return;
my @oid = @_ ? @_ : keys %$ctrl_hash;
my @control = map {@$_} grep $_, @{$ctrl_hash}{@oid}
or return;
# return a list, so in a scalar context we do not just get array length
return @control[0 .. $#control];
}
sub pdu { shift->{pdu} }
sub callback { shift->{callback} }
sub parent { shift->{parent}->outer }
sub mesg_id { shift->{mesgid} }
sub is_error { shift->code }
##
##
##
@Net::LDAP::Add::ISA = qw(Net::LDAP::Message);
@Net::LDAP::Delete::ISA = qw(Net::LDAP::Message);
@Net::LDAP::Modify::ISA = qw(Net::LDAP::Message);
@Net::LDAP::ModDN::ISA = qw(Net::LDAP::Message);
@Net::LDAP::Compare::ISA = qw(Net::LDAP::Message);
@Net::LDAP::Unbind::ISA = qw(Net::LDAP::Message::Dummy);
@Net::LDAP::Abandon::ISA = qw(Net::LDAP::Message::Dummy);
sub Net::LDAP::Compare::is_error {
my $mesg = shift;
my $code = $mesg->code;
$code != LDAP_COMPARE_FALSE and $code != LDAP_COMPARE_TRUE
}
{
package Net::LDAP::Message::Dummy;
our @ISA = qw(Net::LDAP::Message);
use Net::LDAP::Constant qw(LDAP_SUCCESS);
sub new {
my $self = shift;
my $type = ref($self) || $self;
$self = bless {
mesgid => Net::LDAP::Message::NewMesgID(),
}, $type;
$self;
}
sub sync { shift }
sub decode { shift }
sub abandon { shift }
sub code { shift->{resultCode} || LDAP_SUCCESS }
sub error { shift->{errorMessage} || '' }
sub dn { '' }
sub done { 1 }
}
1;
|