On May 27, 2009, at 2:58 AM, Guillaume Rousse wrote:

Chris Ridd a écrit :
which is "passwordTooShort". So... the server seems OK and it must be the perl code that's going wrong somewhere. If you single-step into result->control does it look like it is finding and returning the right thing?
Actually, it returns a list of controls, and the code enforce a scalar context...

Changing the code to
my ($response) = $result->control(LDAP_CONTROL_PASSWORDPOLICY);
is enough to fix the issue. And the documentation is correct, I just misread it :(

Having the method named controlS would have been less error-prone but I guess it's a bit late to change it.

Actually I htink there is a bug. As you only have one control in your response, if you did

  my $response = $result->control;

you would have got the control.

That is because when there are arguments to ->control, the code is returning an array, not a list, which in a scalar context returns its length.

Also, the current code only supports passing one OID, although the docs suggest otherwise

Try this patch

diff --git a/lib/Net/LDAP/Message.pm b/lib/Net/LDAP/Message.pm
index 8e8436f..7df478d 100644
--- a/lib/Net/LDAP/Message.pm
+++ b/lib/Net/LDAP/Message.pm
@@ -210,12 +210,15 @@ sub control {
     }
   }

-  return unless $self->{ctrl_hash};
+  my $ctrl_hash = $self->{ctrl_hash}
+    or return;
+
+  my @oid = @_ ? @_ : keys %$ctrl_hash;
+  my @control = map {...@$_} grep $_, @{$ctrl_has...@oid}
+    or return;

-  @_ ?  exists $self->{ctrl_hash}{$_[0]}
-         ? @{$self->{ctrl_hash}{$_[0]}}
-         : ()
-     : map { @$_ } values %{$self->{ctrl_hash}};
+ # return a list, so in a scalar context we do not just get array length
+  return @control[0 .. $#control];
 }

 sub pdu      {  shift->{pdu}      }

Graham.

Reply via email to