File Coverage

blib/lib/Net/LDAP/Bind.pm
Criterion Covered Total %
statement 9 29 31.0
branch 0 16 0.0
condition 0 11 0.0
subroutine 3 5 60.0
pod 0 1 0.0
total 12 62 19.3


line stmt bran cond sub pod time code
1             # Copyright (c) 1998-2004 Graham Barr . 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 Net::LDAP::Bind;
6              
7 1     1   7 use strict;
  1         2  
  1         41  
8 1         7 use Net::LDAP qw(LDAP_SASL_BIND_IN_PROGRESS LDAP_DECODING_ERROR LDAP_SUCCESS
9 1     1   6 LDAP_LOCAL_ERROR);
  1         2  
10 1     1   18 use Net::LDAP::Message;
  1         1  
  1         450  
11              
12             our $VERSION = '1.05';
13             our @ISA = qw(Net::LDAP::Message);
14              
15             sub _sasl_info {
16 0     0     my $self = shift;
17 0           @{$self}{qw(dn saslctrl sasl)} = @_;
  0            
18             }
19              
20             sub decode {
21 0     0 0   my $self = shift;
22 0           my $result = shift;
23             my $bind = $result->{protocolOp}{bindResponse}
24 0 0 0       or $self->set_error(LDAP_DECODING_ERROR, 'LDAP decode error')
25             and return;
26              
27 0           my $sasl = $self->{sasl};
28 0           my $ldap = $self->parent;
29              
30 0           my $resp;
31 0 0 0       if ($bind->{resultCode} == LDAP_SASL_BIND_IN_PROGRESS or
      0        
32             ($bind->{resultCode} == LDAP_SUCCESS and $bind->{serverSaslCreds})) {
33 0 0         $sasl or $self->set_error(LDAP_LOCAL_ERROR, 'no sasl object'), return;
34             ($resp) = $sasl->client_step($bind->{serverSaslCreds})
35 0 0         or $self->set_error(LDAP_DECODING_ERROR, 'LDAP decode error'), return;
36             }
37              
38             # Put the new layer over the raw socket, to get rid of any old layer,
39             # but only if we will be using a new layer. If we rebind but don't
40             # negotiate a new security layer, the old layer remains in place.
41 0 0 0       if ($sasl and $bind->{resultCode} == LDAP_SUCCESS) {
42 0 0         $sasl->property('ssf', 0) if !$sasl->property('ssf');
43             $ldap->{net_ldap_socket} = $sasl->securesocket($ldap->{net_ldap_rawsocket})
44 0 0         if ($sasl->property('ssf'));
45             }
46              
47             return $self->SUPER::decode($result)
48 0 0         unless $bind->{resultCode} == LDAP_SASL_BIND_IN_PROGRESS;
49              
50             # tell our LDAP client to forget us as this message has now completed
51             # all communications with the server
52 0           $ldap->_forgetmesg($self);
53              
54 0           $self->{mesgid} = Net::LDAP::Message->NewMesgID(); # Get a new message ID
55              
56             $self->encode(
57             bindRequest => {
58             version => $ldap->version,
59             name => $self->{dn},
60             authentication => {
61             sasl => {
62             mechanism => $sasl->mechanism,
63             credentials => $resp
64             }
65             },
66             control => $self->{saslcontrol}
67 0           });
68              
69 0           $ldap->_sendmesg($self);
70             }
71              
72             1;