> sub ldapsearch {
>   $ldap_con = new Net::LDAPapi($ldap_host);
>   if ($ldap_con == -1) { "Unable to Open LDAP Connection to $ldap_host"; }

Shouldn't the line above be:
    warn "Unable to Open LDAP Connection to $ldap_host" if ($ldap_con == -1);
or
    die "Unable to Open LDAP Connection to $ldap_host" if ($ldap_con == -1);
??

>   $status = $ldap_con->bind_s("cn=Directory Manager", $ldap_password);
>   @attrs = ();
>   if ($choice eq "uid") {
>     $filter = "$type=$search_str";
>     $status = $ldap_con->search_s($ldap_dn,LDAP_SCOPE_SUBTREE,$filter,\@attrs,0);
>     if ($status != LDAP_SUCCESS) {  $ldap_con->errstring; }
>     %ldap_exists = %{$ldap_con->get_all_entries};
>     foreach $result (keys %ldap_exists) {
>       $value = "@{$ldap_exists{$result}{uid}}";
>     }
>     if ($value eq $search_str) {
>       return 1;
>     }
>     return(0);
>   } else {
>     $filter = "$type=*-$search_str";
>     $status = $ldap_con->search_s($ldap_dn,LDAP_SCOPE_SUBTREE,$filter,\@attrs,0);
>     if ($status != LDAP_SUCCESS) {  $ldap_con->errstring; }
>     %ldap_exists = %{$ldap_con->get_all_entries};
>     foreach $result (keys %ldap_exists) {
>           $value = "@{$ldap_exists{$result}{uid}}";
>     }
>     if ($value eq $search_str) {
>       return 1;
>     }
>     return(0);
>   }
> }
> 

Also the ``if ($choice eq "uid")'' has duplicated code in then and else
branchs.  As a suggestion of a more compact code:

sub ldapsearch {
  my $ldap_con = new Net::LDAPapi($ldap_host);
  warn "Unable to Open LDAP Connection to $ldap_host"
      if ($ldap_con == -1);
  my @attrs = ();
  my $filter = ($choice eq "uid") ? "$type=$search_str" : "$type=*-$search_str";
  $ldap_con->bind_s("cn=Directory Manager", $ldap_password);
  my $status = $ldap_con->search_s($ldap_dn, LDAP_SCOPE_SUBTREE, $filter, \@attrs, 0);
  $ldap_con->errstring
      if ($status != LDAP_SUCCESS);
  %ldap_exists = %{$ldap_con->get_all_entries};
  foreach $result (keys %ldap_exists) {
      $value = "@{$ldap_exists{$result}{uid}}";
  }
  return ($value eq $search_str) ? 1 : 0;
}

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to