File: Bind.pm

package info (click to toggle)
libnet-ldap-perl 1%3A0.4400-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,484 kB
  • sloc: perl: 13,645; sh: 16; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,858 bytes parent folder | download | duplicates (3)
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
# 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 Net::LDAP::Bind;

use strict;
use Net::LDAP qw(LDAP_SASL_BIND_IN_PROGRESS LDAP_DECODING_ERROR LDAP_SUCCESS
		 LDAP_LOCAL_ERROR);
use Net::LDAP::Message;
use vars qw(@ISA $VERSION);

$VERSION = "1.03";
@ISA = qw(Net::LDAP::Message);

sub _sasl_info {
  my $self = shift;
  @{$self}{qw(dn saslctrl sasl)} = @_;
}

sub decode {
  my $self = shift;
  my $result = shift;
  my $bind = $result->{protocolOp}{bindResponse}
     or $self->set_error(LDAP_DECODING_ERROR,"LDAP decode error")
    and return;

  my $sasl = $self->{sasl};
  my $ldap = $self->parent;

  my $resp;
  if ($bind->{resultCode} == LDAP_SASL_BIND_IN_PROGRESS or
     ($bind->{resultCode} == LDAP_SUCCESS and $bind->{serverSaslCreds})) {
	$sasl or $self->set_error(LDAP_LOCAL_ERROR,"no sasl object"), return;
	($resp) = $sasl->client_step($bind->{serverSaslCreds})
	  or $self->set_error(LDAP_DECODING_ERROR,"LDAP decode error"), return;
  }

  $ldap->{net_ldap_socket} = $sasl->securesocket($ldap->{net_ldap_socket})
    if $sasl and $bind->{resultCode} == LDAP_SUCCESS;

  return $self->SUPER::decode($result)
    unless $bind->{resultCode} == LDAP_SASL_BIND_IN_PROGRESS;

  # tell our LDAP client to forget us as this message has now completed
  # all communications with the server
  $ldap->_forgetmesg($self);

  $self->{mesgid} = Net::LDAP::Message->NewMesgID(); # Get a new message ID

  $self->encode(
    bindRequest => {
    version => $ldap->version,
    name    => $self->{dn},
    authentication => {
      sasl    => {
        mechanism   => $sasl->mechanism,
        credentials => $resp
      }
    },
    control => $self->{saslcontrol}
  });

  $ldap->_sendmesg($self);
}

1;