Ryan, Thanks for the reply. Here are the answers to your questions.
Not sure what you mean by "sort extension". I set the "searchFlags" to 0x41 for the attribute that I'm trying to index (cn) on the ADAM. I also used the sort control and vlv control calls (see below).
With ldap.exe, see the Browse/Virtual List View menu. I used this to do ldp vlv to the ADAM.
The actual code based on the link in my original message (I've tried many variations with no luck):
LDAP
*ld;
ULONG ldaperr;
// Create the VLV control and send it to the server.
LDAPVLVInfo vlvInfo;
PLDAPControl pvlvctrl;
PLDAPControl psortctrl;
PLDAPControl ctrlArr[3];
// Create a sort control and attach it.
LDAPSortKey sortkeys;
PLDAPSortKey sortkeyList[2];
PLDAPMessage pRes;
PLDAPControl *pvlvresponse = NULL;
ULONG targetpos =0;
ULONG listcount = 0;
int errcode = LDAP_SUCCESS;
PBERVAL context = NULL;
char *attrs[] = {"displayName", NULL }; /* Attributes to return */
ld = ldap_open("myhostname.com", 5500);
if (ld)
{
printf("Open succeeded\n");
}
else
{
printf("Open failed\n");
return 1;
}
ldaperr = ldap_bind_s(ld, "myCredentials", "myPassword", LDAP_AUTH_SIMPLE);
if (ldaperr == LDAP_SUCCESS)
{
printf("Bind succeeded\n");
}
else
{
printf("Bind failed with 0x%x 0x%x\n", ldaperr, GetLastError);
ldap_unbind(ld);
return 1;
}
// Enter the members of the VLV control.
vlvInfo.ldvlv_after_count = 1;
vlvInfo.ldvlv_attrvalue = NULL;
vlvInfo.ldvlv_before_count = 1;
vlvInfo.ldvlv_context = NULL;
vlvInfo.ldvlv_count = 0;
vlvInfo.ldvlv_extradata = NULL;
vlvInfo.ldvlv_offset = 2;
vlvInfo.ldvlv_version = LDAP_VLVINFO_VERSION;
ldaperr = ldap_create_vlv_control( ld,
&vlvInfo,
TRUE,
&pvlvctrl);
printf("Create VLV control returned 0x%x\n",ldaperr);
if (LDAP_SUCCESS != ldaperr)
return 1;
sortkeys.sk_attrtype = "cn";
sortkeys.sk_matchruleoid = NULL;
sortkeys.sk_reverseorder = FALSE;
sortkeyList[0] = &sortkeys;
sortkeyList[1] = NULL;
ldaperr = ldap_create_sort_control( ld,
sortkeyList,
TRUE,
&psortctrl
);
printf("Create Sort control returned 0x%x\n",ldaperr);
if (LDAP_SUCCESS != ldaperr)
return 1;
ctrlArr[0] = psortctrl;
ctrlArr[1] = pvlvctrl;
ctrlArr[2] = NULL;
// Send the VLV control, with a search request, to the server.
ldaperr = ldap_search_ext_s( ld,
"myBaseForSearch",
LDAP_SCOPE_SUBTREE,
"(cn=joe*)",
attrs,
1,
ctrlArr,
NULL,
NULL,
0,
&pRes
);
printf("Ldap search returned 0x%x\n",ldaperr);
// Choose the control returned from the server.
ldaperr = ldap_parse_result( ld,
pRes,
NULL,
NULL,
NULL,
NULL,
&pvlvresponse,
FALSE
);
printf("Ldap parse_result returned 0x%x\n",ldaperr);
// Parse the VLV control returned from the server.
ldaperr = ldap_parse_vlv_control( ld,
pvlvresponse,
&targetpos,
&listcount,
&context,
&errcode
);
printf("Ldap parse vlv control returned 0x%x\n",ldaperr);
printf("TargetPos = %d\n", targetpos);
printf("ListCount = %d\n", listcount);
printf("errcode = 0x%x\n", errcode);
ldap_unbind(ld);
ldap_control_free(pvlvctrl);
ldap_control_free(psortctrl);
ldap_msgfree(pRes);
ldap_controls_free(pvlvresponse);
ber_bvfree(context);
return 0;