Closed Bug 12884 Opened 25 years ago Closed 25 years ago

Controls don't work with API.xs

Categories

(Directory :: PerLDAP, defect, P1)

defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: kmccarth, Assigned: kmccarth)

Details

"Eric C. Hagberg" <hagberg@ms.com> writes:

Are there any examples for PerLDAP using controls, specifically VLV or
persistent searches?

Tried a few things after reading the C SDK and the Mozilla::LDAP::API
docs, but I can't seem to even get a successful result from a
ldap_create_sort_control() or ldap_create_virtuallist_control() call.
They always seem to return a "Bad parameter to an ldap routine" error.

Thanks,
-Eric
Status: NEW → ASSIGNED
Eric writes:

Unless I'm mistaken, I believe there's a bug wrt creating controls, at least
from what I can see. The following snippet
of code will generate a "Bad parameter to an ldap routine" error for the
ldap_create_sort_control() call:

     $rc = ldap_create_sort_keylist( $sortkeylist, "sn" );
     if ($rc != LDAP_SUCCESS) {
       print "problem with keylist\n";
       print "err: ".ldap_err2string( $rc )."\n";
     }

     $rc = ldap_create_sort_control( $ld, $sortkeylist, 1, $sortctrl );
     if ($rc != LDAP_SUCCESS) {
       print "problem with sort control\n";
       print "err: ".ldap_err2string( $rc )."\n";
     }


That shouldn't happen if the $sortkeylist is being generated by
ldap_create_sort_keylist, should it?

Thanks,
-Eric
Priority: P3 → P1
Kevin McCarthy wrote:
>
> Hmmmm...  this is a tricky one.  In Perl, the return value is pushed
> onto the stack as ST(0).  But the function ldap_create_sort_keylist
> wants to modify its first argument, which by coincidence in Perl is also
> located at ST(0).
>

At the risk of looking even more incompetant, I'm replying to my own
post.  Please ignore my previous post rambling about ST(0) stuff - I was
completely, utterly, wrong.  That's not the problem (thank goodness).
Sorry about that.

I believe the problem is actually the API.xs typemaps for the
LDAPControls.

Basically, the functions: ldap_create_persistentsearch_control,
ldap_create_sort_control, and ldap_create_virtuallist_control had the
wrong prototypes for the LDAPControl parameters.  That's easy to fix,
and I've attached the patch file below.

The problem is, once you've created your controls, you're probably going
to want to do something with them like

ldap_search_ext_s($ld, ........, [$control1, $control2],  ....);

I don't think that's going to work - no one has done any work yet in
API.xs to map the array ref to a NULL terminated LDAPControl **, and I
don't know what other issues there are involved in this.  I've got to
sit down with Leif and Michelle and make sure this gets done properly.

In short, we've got a bit of work to do on the LDAPControl stuff.  Sorry
this didn't get noticed and fixed earlier.  :-(

-Kevin

Index: API.xs
===================================================================
RCS file: /cvsroot/mozilla/directory/perldap/API.xs,v
retrieving revision 1.17
diff -c -r1.17 API.xs
*** API.xs      1999/08/24 22:30:41     1.17
--- API.xs      1999/08/31 06:33:34
***************
*** 785,791 ****
        int             changesonly
        int             return_echg_ctrls
        char            ctrl_iscritical
!       LDAPControl **  ctrlp = NO_INIT
        OUTPUT:
        RETVAL
        ctrlp
--- 785,791 ----
        int             changesonly
        int             return_echg_ctrls
        char            ctrl_iscritical
!       LDAPControl *   &ctrlp = NO_INIT
        OUTPUT:
        RETVAL
        ctrlp
***************
*** 795,801 ****
        LDAP *          ld
        LDAPsortkey **  sortKeyList
        char            ctrl_iscritical
!       LDAPControl **  ctrlp = NO_INIT
        OUTPUT:
        RETVAL
        ctrlp
--- 795,801 ----
        LDAP *          ld
        LDAPsortkey **  sortKeyList
        char            ctrl_iscritical
!       LDAPControl *   &ctrlp = NO_INIT
        OUTPUT:
        RETVAL
        ctrlp
***************
*** 812,818 ****
  ldap_create_virtuallist_control(ld,ldvlistp,ctrlp)
        LDAP *          ld
        LDAPVirtualList *ldvlistp
!       LDAPControl **  ctrlp = NO_INIT
        OUTPUT:
        RETVAL
        ctrlp
--- 812,818 ----
  ldap_create_virtuallist_control(ld,ldvlistp,ctrlp)
        LDAP *          ld
        LDAPVirtualList *ldvlistp
!       LDAPControl *   &ctrlp = NO_INIT
        OUTPUT:
        RETVAL
        ctrlp
Eric reports that this patch fixes the "bad argument" problem.  But, as I
thought, we have the problem that none of the _ext_ functions will work.  I need
to add a typemap for LDAPControl **  -> to convert to and from a Perl AV.

Also need to work with Michelle and Leif to make sure this get's done "the right
way".
Status: ASSIGNED → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
There were many, many little problems in API.xs.  Memory leaks,
incorrect parameters, and missing typemaps.  I created a large patchfile,
and commited it to devel-branch-1_9.  I also send the patch to Eric, who says
it seems to be working so far.
You need to log in before you can comment on or make changes to this bug.